ASP.NET SMTP System.net.mail

Sunday, November 08, 2015 Unknown 0 Comments

Here is an example. VB.net
It is a smtp mail out from a contact form.
When upgrading to .net 2.0 you will need to move to system.net.mail


Dim Message1 As New System.Net.Mail.MailMessage
Dim MsgBody As New System.Text.StringBuilder(4000)
MsgBody.Insert(0, "
")

MsgBody.Append("This Message is from: " + Me.TextBox1.Text.ToString)
MsgBody.Append("
")
MsgBody.Append(Me.TEXTAREA1.InnerText().ToString)
Try
Dim str_from As New System.Net.Mail.MailAddress(Me.TextBox1.Text.ToString)
Dim mailto As New System.Net.Mail.MailAddress("Your@address.com")
With Message1
.To.Add(mailto)
.From = str_from
.Body = MsgBody.ToString()
.Subject = "Message From ContactUS Form"
.IsBodyHtml = True
.Headers.Add("Content-Type", "multipart/alternative;")
End With
Dim smtp As New System.Net.Mail.SmtpClient
Try
smtp.Host = "mail.itdev.ca"
smtp.Send(Message1)
Return True
Catch ex As Exception
Return False
End Try
Catch ex As Exception
End Try

0 comments :

Powered by Blogger.