Sending an e-mail message is a simple process using the Internet Mail control, and typically involves calling a single method, SendMessage. There are a number of variants for this method which accept different arguments, but for most applications you can simply invoke the method with no arguments:
If InternetMail1.SendMessage() Then
MsgBox("The message has been submitted for delivery")
Else
MsgBox(InternetMail1.LastErrorString, MsgBoxStyle.Exclamation)
Exit Sub
End If
In most cases, that is all that’s required to send the message. The class will automatically extract the e-mail addresses from the To, Cc, and Bcc properties and deliver the message to those recipients. However, there may be circumstances where you wish to send a message to a different set of addresses. The SendMessage method has several implementations that enable you to control the sender, recipient and even the contents of the message itself.
If you need to send a message through a relay server, then you can simply initialize those property values before calling the SendMessage method. For example:
InternetMail1.RelayServer = "mail.server.com"
InternetMail1.RelayPort = 25
InternetMail1.UserName = "username"
InternetMail1.Password = "secret"
InternetMail1.Options = InternetMailOptions.optionAuthLogin
If InternetMail1.SendMessage() Then
MsgBox("The message has been submitted for delivery")
Else
MsgBox(InternetMail1.LastErrorString, MsgBoxStyle.Exclamation)
Exit Sub
End If
In this case, the message will be submitted to the relay server mail.server.com, and the client session will be authenticated with a username and password. This is the configuration that most service providers require, ensuring that the message is being submitted by a legitimate subscriber to their service.