Monday, September 6, 2010

VB.NET Send Mail



imports System.Net.Mail
Dim mail As New MailMessage()
mail.From = New MailAddress("" & txtfrm.Text & "")
mail.To.Add("" & txtto.Text & "")

mail.Subject = "" & txtsub.Text & ""
mail.Body = "" & txtmsg.Text & ""
mail.IsBodyHtml = True

Dim file As String = "" & txtatch.Text & ""
If Not file = "" Then
Dim MsgAttach As New Attachment(file)
mail.Attachments.Add(MsgAttach)
End If

Dim smtp As New SmtpClient("mail.suprol.com")
smtp.Send(mail)
lblmail.Text="mail sent successfully..!!"
//With a copy send to mailsender with date time
Dim mail As New MailMessage()
Dim mailrep As New MailMessage()

mail.From = New MailAddress("" & txtfrm.Text & "")
mail.To.Add("" & txtto.Text & "")

mailrep.From = New MailAddress("" & txtfrm.Text & "")
mailrep.To.Add("" & txtfrm.Text & "")
mailrep.Subject = "Mail sent To" & "" & " " & txtto.Text & ""
mailrep.Body = "Your Mail successfully Sent To" & " " & "" & txtto.Text & "" & " " & "Date and Time was : " & " " & "" & DateTime.Now() & "" & " " & "With Attachment File Name :" & " " & "" & txtatch.Text & ""
mailrep.IsBodyHtml = True


mail.Subject = "" & txtsub.Text & ""
mail.Body = "" & txtmsg.Text & ""
mail.IsBodyHtml = True
Dim filerep As String = "" & txtatch.Text & ""
Dim file As String = "" & txtatch.Text & ""
If Not file = "" Then
Dim MsgAttach As New Attachment(file)
mail.Attachments.Add(MsgAttach)
mailrep.Attachments.Add(MsgAttach)
End If

Dim smtp As New SmtpClient("mail.suprol.com")
smtp.UseDefaultCredentials = False
smtp.Port = 2525
smtp.Send(mail)
smtp.Send(mailrep)

No comments: