In this article I m describing how can we send e-mail to anyone after creating an account in Gmail.
We have to pass the parameters in MailMessage, NetworkCredential, SmptClient. I am accessing the before mentioned parameters from web.config file this is because in future if we need to change the E-mail id, and smtp address then we can change in web.config file without interrupt the whole website. We will enter the values under the Appsettings. Hope this article will help you.
create a any method name sendmail()
Public Sub sendmail()
Try
Dim mail As New System.Net.Mail.MailMessage(ConfigurationManager.AppSettings(“from”), email, txt_from_email.Text, txt_mesg.Text)
Dim mailAuthentication As New System.Net.NetworkCredential(ConfigurationManager.AppSettings(“id”), ConfigurationManager.AppSettings(“pswd”))
Dim mailClient As New System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings(“smtp”), ConfigurationManager.AppSettings(“port”))
‘Enable SSL
mailClient.EnableSsl = True
mailClient.UseDefaultCredentials = False
mailClient.Credentials = mailAuthentication
mailClient.Send(mail)
lbl_mesg.Visible = True
lbl_mesg.ForeColor = Drawing.Color.Blue
lbl_mesg.Text = “Your Message has been sent sucessfully”
txt_mesg.Text = “”
Catch ex As Exception
lbl_mesg.Visible = True
lbl_mesg.Text = “Unable to send the message.”
End Try
End Sub
++++++++++++++++++++++++++
AND IN CONFIG FILE
< appSettings>
< add key=”from” value=”urs@mail.com”/>
< !– for password –>
< add key=”id” value=”ursid”/>
< add key=”pswd” value=”urspassword”/>
< !– put port and smpt values–>
< add key=”port” value=”587″/>
< add key=”smtp” value=”smtp.gmail.com”/>
< /appSettings>
++++++++++++++++++++++++++
With Regards
Vik



Pingback: Philips