Module
Module1 Sub Main() 'This will contain the actual message to send. Dim message As System.Net.Mail.MailMessage
'The next class is the SMTPClient... ' 'The Simple Mail Tranfer Protocol client with the Host and Port number to use. You will want to change these settings to what you need to use. Dim smtp As New System.Net.Mail.SmtpClient("smtp.gmail.com", 587)
' The code above has created and setup the SMTP Client. Googles gMail actually requires 587 to be the port number from what I understand. You can leave out the Port number if your SMTP doesn't require a specific port. Also remember if you are not using the GMail to send your messages then you need to change the Host parameter to the Host you are going to use to send your mails. Example: "mysmtp.host.com" 'The final Class is the Attachment class... ' 'Will contain the attachment info to send with the message. Dim attach As System.Net.Mail.Attachment Dim sFrom As String, sTo As String, sSsub As String, sMsg As String Dim sFile As String
sFrom =
"user1.edel@gmail.com"sTo =
"tgkprog@gmail.com"sFile =
"D:\\j\\j5\\h\\tgk\\net\\eml1\\e2\\emlcmds.txt"sSsub =
"t w"sMsg =
"a" ' 'Setup the mail message using 4x Textbox controls that contains the From/To/Subject/Message-Body info. You just need to set it up the way you want it to be...message =
New System.Net.Mail.MailMessage(sFrom, sTo, sSsub, sMsg) 'The code below will check a attachment to make sure the file exists.. ' 'Need to make sure the attachment exists before adding it to the message. If My.Computer.FileSystem.FileExists(sFile) Thenattach =
New System.Net.Mail.Attachment(sfile)message.Attachments.Add(attach)
End If'Now set the Secure Socket Layer feature which is required to be 'True' if you use Googles gMail as your host... ' 'Use Secure Socket Layer to Encrypt the connection for sending the mail. This needs be set to "True" if you plan on using GMail as your host.
smtp.EnableSsl =
True 'And now your can set up your Credentials for your Login info. (Username and Password) ' 'Setup your account information for authorization...smtp.Credentials =
New System.Net.NetworkCredential("user1.edel@gmail.com", "pwd")
'Now that the Mail setup is completed. The only thing left to do is Send your message.
Try ' 'Send the mail message that was setup.
smtp.Send(message)
' 'Usually it was successful in sending the message if it makes it to here 'Otherwise it should throw a error message from the Catch exception below. 'MessageBox.Show("Well, the mail message appears to have been a success!", " Successful?", MessageBoxButtons.OK, MessageBoxIcon.Information)Console.WriteLine(
"ok") Catch exc As Net.Mail.SmtpException 'MessageBox.Show(exc.StatusCode.ToString, " Something Happened?", MessageBoxButtons.OK, MessageBoxIcon.Error)Console.WriteLine(exc.StatusCode.ToString)
End Try End SubEnd
Module