About Us Contact Us
ServicesProductsWeb HostingTutorialsDownloadsPortfolio

 
Tutorials
 
Sending Mails in VB.net
Sending mails in VB.Net is much easier than the previos versions of VB applications.
I'm going to show an example of how we can send mails in VB.net

We need to make use of System.Web.Mail namespace for sending the mails.

You first import this namespace on top of your module

Imports System.Web.Mail

Add the following sub routine to your module

Public Sub SendMail(ByVal SendTo As String, _
ByVal Subject As String, _
ByVal Body As String, _
ByVal AttachmentFile As String)


Dim oMsg As MailMessage = New MailMessage
oMsg.From = "someone@somewhere.com"
oMsg.To = SendTo
oMsg.Subject = Subject
oMsg.Body = Body
If AttachmentFile <> "" Then
If (File.Exists(AttachmentFile) = True) Then
Dim oAttch As MailAttachment = New
MailAttachment(AttachmentFile)
oMsg.Attachments.Add(oAttch)
End If
End If
'you may add your smtp server address here
SmtpMail.SmtpServer = "mail.yourdomain.com"
SmtpMail.Send(oMsg)

End Sub


Now you can call the procedure using following code. Please remember to
change the SMTP Server
address in the above procedure.

SendMail("to@somedomain.com","Subject line", "Body Text","c:\attach\somefile.doc")


Feel free to edit add more features to the code and use in your application.

Happy Programming!!



Author: J Jacob
Send any comments at: jeena@lizratechnologies.com
   
Home| Links | Services | Products | Web Hosting | Tutorials | Downloads | Portfolio | Contact Us | Terms and conditions