//created by Srinivasaprabhu.N//
Imports System.Data
Imports System.Configuration
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports System.Net
Imports System.Net.Mail
Public Class Email
Public Sub New()
End Sub
Public Shared Sub sendMail(ByVal [to] As String, ByVal from As String, ByVal subject As String, ByVal body As String)
Dim client As New SmtpClient("smtp_clntname", portnumber)
client.Credentials = New NetworkCredential("userid", "passwrd")
client.EnableSsl = True
''mail details
Dim msg As New MailMessage()
Try
msg.From = New MailAddress(from)
msg.[To].Add([to])
' msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Subject = subject
msg.CC.Add("mailid")
msg.IsBodyHtml = True
msg.BodyEncoding = System.Text.Encoding.UTF8
msg.Body = body
msg.Priority = MailPriority.Normal
client.Send(msg)
Catch exp As Exception
''''This runs the backup plan
SendMailAlt([to], from, subject, body)
End Try
End Sub
Private Shared Sub SendMailAlt(ByVal [to] As String, ByVal from As String, ByVal subject As String, ByVal body As String)
Dim Mail As New System.Web.Mail.MailMessage()
Mail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ("smtpname")
Mail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 //2 shows without authendication
Mail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = "portnumber" //ex:25
Mail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = "true"
Mail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
' Edit username & password
Mail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "uid"
Mail.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "pwd"
Mail.[To] = [to]
Mail.From = from
Mail.Cc = "mailid"
Mail.Subject = subject
Mail.Body = body
Mail.BodyFormat = System.Web.Mail.MailFormat.Html
System.Web.Mail.SmtpMail.SmtpServer = "smtpnam"
System.Web.Mail.SmtpMail.Send(Mail)
End Sub
End Class
No comments:
Post a Comment