VB.net code to send email without attachment

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 297
The below code will do so

Public Shared Sub SendEmailWithoutAttachment(smptTuple As Tuple(Of String, Integer, String, String), emailInfoTuple As Tuple(Of String, String, String, String, String))
Try
Dim smptHost As String = smptTuple.Item1
Dim smptPort As Integer = smptTuple.Item2
Dim smptUser As String = smptTuple.Item3
Dim smptPassword As String = smptTuple.Item4
Dim fromEmailAddress As String = emailInfoTuple.Item1
Dim toEmailAddress As String = emailInfoTuple.Item2
Dim ccEmailAddress As String = emailInfoTuple.Item3
Dim subject As String = emailInfoTuple.Item4
Dim body As String = emailInfoTuple.Item5


Dim mailMsg As New MailMessage()
Dim emailAddress As New MailAddress(toEmailAddress)
mailMsg.[To].Add(emailAddress)

For Each address As var In ccEmailAddress.Split(New () {","}, StringSplitOptions.RemoveEmptyEntries)
mailMsg.CC.Add(address)
Next

mailMsg.From = New MailAddress(fromEmailAddress)

mailMsg.Subject = subject
mailMsg.Body = body
mailMsg.IsBodyHtml = True

' Init SmtpClient
Dim smtpClient As New SmtpClient(smptHost, smptPort)
smtpClient.EnableSsl = False
Dim credentials As New System.Net.NetworkCredential(smptUser, smptPassword)
smtpClient.Credentials = credentials

'send email

smtpClient.Send(mailMsg)
Catch ex As Exception
Throw ex
End Try
End Sub

Comments or Responses

Login to post response