How to send Mail using VB.NET

This code showz hot to send a mail with attachment in

Public Sub MailFormat(ByVal fromAddress As String, ByVal toAddress As String, ByVal body As String, ByVal subject As String, ByVal attachFile As String)

'Format written to send mail with attachment

Dim message As MailMessage = New MailMessage()
message.IsBodyHtml = True
message.Subject = subject
message.From = New MailAddress(fromAddress)
message.Body = body.ToString()
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure

If Not attachFile Is Nothing Then

Dim attachFiles As Attachment = New Attachment(attachFile)

End If

Dim smtp As SmtpClient = New SmtpClient(ConfigurationManager.AppSettings(NAPResource.hostName), ConfigurationManager.AppSettings(NAPResource.portNumber))


End Sub


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: