How to use Asp.net
  • Home
  • About us
  • Disclaimer
  • joy of helping
KEEP IN TOUCH

How to send E-mail in Asp.net Vb.net

Mar27
2011
1 Comment Written by vikram

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

Posted in Asp.net
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
« Send a web form as a Email asp.net vb.net
» How to create thumbnail of images in asp.net vb.net

One comment on “How to send E-mail in Asp.net Vb.net”

  1. Pingback: Philips

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Joy of Helping

Any sort of help to the children who are fatherless, poor & are from far-off areas.
Joy of Helping

Facebook Link

Asp dot Net ,Ajax,Xml.

Recent Posts

  • ROW_NUMBER(), NTILE(), partition by, Duplicate Records, CTE sql server 2008
  • How to get second highest Salary sql server 2008
  • Insert values, insert into, insert default value, insert execute and select into sql server 2008
  • How to Bind GridView with SqlDataReader in Asp.net
  • how to attach files to email without storing on disk using Asp.net FileUpload control

Recent Comments

  • Anonymous on ROW_NUMBER(), NTILE(), partition by, Duplicate Records, CTE sql server 2008
  • dhananjay on How to use GridView with Insert, Edit, Update, Delete the Ado.net way C#
  • dev on How can we limit the characters in multiline textbox asp.net using JavaScript
  • navneet on How to display image in Image control after upload on the server asp.net C#
  • AnhVu on How to do Shopping Cart in Asp.net C#

Archives

  • February 2013
  • September 2012
  • April 2012
  • January 2012
  • October 2011
  • August 2011
  • May 2011
  • April 2011
  • March 2011

Categories

  • Asp.net
  • jQuery
  • Sql Server

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

EvoLve theme by Theme4Press  •  Powered by WordPress How to use Asp.net