- Now you will learn how to send email using a VB.net program. This can be done in different ways.
- First two code segments shows how a mail can be Configured and sent using the default mail server using VB code.
- This program sends emails to a recipient address(s) that you specify. You have to give the mail server (SMTP Server) name or the IP address correctly.
- If you are planned to send the mail using the button1_click() or button2_click() methods, first make a reference to the System.web.dll file (because the example uses classes in the system.web.mail namespace). project->Add reference...
- Third code segment [button3_click()] starts the MS OUTLOOK and then user can use that application to send and receive emails.
- Codings...
Dim email As New System.Web.Mail.MailMessage
email.To = "ABSReceiver@abc.com"
email.From = "ABcSender@abc.com"
email.Body = "Hi!!!!!! "
email.Subject = "Testing"
email.BodyFormat = Web.Mail.MailFormat.Text
System.Web.Mail.SmtpMail.SmtpServer = "1.1.1.1" 'SMTP Server IP Address
System.Web.Mail.SmtpMail.Send(email)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
System.Web.Mail.SmtpMail.SmtpServer = "1.1.1.1" 'SMTP Server IP Address
System.Web.Mail.SmtpMail.Send("ABSReceiver@abc.com", "ABcSender@abc.com", "Testing", "Hi!!!!!! ")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim a As Object
a = Shell("c:\Program Files\Outlook Express\msimn.exe", AppWinStyle.NormalFocus)
End Sub