THIS IS VERY SIMPLE METHOD TO SEND MAIL TO ANYONE USING VB.NET
FOLLOW THE FOLLOWING STEPS.
STEP--1
IMPORT FOLLOWING FILES
Imports System.Net.Mail
STEP--2
CALL FUNCTION AS FOLLOW:
call function in your project and pass the parameters.
Private Function SEND_MAIL(ByRef strto As String, ByRef strcc As String, ByRef strsubject As String, ByRef StrBody As String, ByRef straattch As String) As Boolean
Try
Dim FILE As String
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Dim mail_to As String
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("abc@abc.com", "123") ' enter you email address and then password your email.
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "www.gmail.com" ' pass your email domain
mail_to = strto ' pass the email id whom you want to send mail.
e_mail.CC.Add("abc@abc.com") ' to send mail with cc
e_mail = New MailMessage()
e_mail.From = New MailAddress("abcd@iolcp.com") ' email address of sender
FILE = straattch ' this is for sending attachment pass the path of the file.
e_mail.Attachments.Add(New Attachment(FILE))
e_mail.To.Add(mail_to)
e_mail.Bcc.Add("123@123.com")
e_mail.Subject = strsubject
e_mail.IsBodyHtml = True
'StrBody = StrBody & "Dear Sir/Madam,<br /><br /> i am sending you mail for testing purpose." & "<br/>" & "<br/>" & "Kindly check and revert back" & "<br /><br />"
e_mail.Body = StrBody
Smtp_Server.Send(e_mail)
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
End Function
FOLLOW THE FOLLOWING STEPS.
STEP--1
IMPORT FOLLOWING FILES
Imports System.Net.Mail
STEP--2
CALL FUNCTION AS FOLLOW:
call function in your project and pass the parameters.
Private Function SEND_MAIL(ByRef strto As String, ByRef strcc As String, ByRef strsubject As String, ByRef StrBody As String, ByRef straattch As String) As Boolean
Try
Dim FILE As String
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Dim mail_to As String
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("abc@abc.com", "123") ' enter you email address and then password your email.
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "www.gmail.com" ' pass your email domain
mail_to = strto ' pass the email id whom you want to send mail.
e_mail.CC.Add("abc@abc.com") ' to send mail with cc
e_mail = New MailMessage()
e_mail.From = New MailAddress("abcd@iolcp.com") ' email address of sender
FILE = straattch ' this is for sending attachment pass the path of the file.
e_mail.Attachments.Add(New Attachment(FILE))
e_mail.To.Add(mail_to)
e_mail.Bcc.Add("123@123.com")
e_mail.Subject = strsubject
e_mail.IsBodyHtml = True
'StrBody = StrBody & "Dear Sir/Madam,<br /><br /> i am sending you mail for testing purpose." & "<br/>" & "<br/>" & "Kindly check and revert back" & "<br /><br />"
e_mail.Body = StrBody
Smtp_Server.Send(e_mail)
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
End Function
No comments:
Post a Comment