This article explains how to send email in asp.net AND vb.net send email functionality. First it will take you through step by step process of creating asp.net c# project “asp.net send email“ and later also shows code for vb or vba send email functionality.
Send Email through Php Web application using your Gmail, yahoo, Hotmail Accounts
Steps on how to send email in asp.net
(1) Open Visual studio. Go to File -> new website -> select Asp.net website and give name as “send email in asp.net c#”.
(2) Select visual c# as back hand language and click OK.
(3) You will see Solution Explorer for new website at right side of window.
(4) Double Click on the Default.aspx page inside solution explorer. Then select Design view.
(5) Create form as shown in below figure. (Use table to create form)
|asp.net and vba send email UI|
Id’s of Textbox, Label & Button
username textbox : txtUsr
password textbox : txtPass
To textbox:- txtTo
From textbox : txtFrom
Subject textbox : txtSub
Body textbox : txtBody
Label Delivery Report : lblReport
Button : Button1
(6) Set password textbox’s Textmode property to password for security purpose.
(7) Now Double click on button.
(8) You can see that Default.aspx.cs file is opened and cursor is in the Button1_click Event.
Include Namespace for asp.net send email project or code
Write below code in the event Button1_click
asp.net send email | send email in asp.net code
MailMessage mm =new MailMessage(); // To initialize new message
mm.To.Add(txtTo.Text ); // For receiver's address
mm.From = new MailAddress(txtFrom.Text); // For sender's address
mm.Subject = txtSub.Text; // For Subject of the mail
mm.Body = txtBody.Text; // For Body of the mail
mm.IsBodyHtml = true;
SmtpClient ss=new SmtpClient("smtp.gmail.com",587);
ss.Credentials = new System.Net.NetworkCredential(txtUsr.Text, txtPass.Text);
ss.EnableSsl = true; // For Secure connection
ss.Send(mm); // For sending message
lblReport.Text = "message sent"; // For delivery report
catch (Exception ex)
lblReport.Text = ex.Message;
(9)This is the code for sending mail from Gmail address to any other mail address.
If you want to send mail using Yahoo, Hotmail account then just change outgoing mail server accordingly.
If you are using Hotmail than port no. will be 587 and host will be smtp.live.com
If you are using Yahoo than port no. will be 587 and host will be smtp.mail.yahoo.com
If you are using Gmail than port no. will be 587 and host will be smtp.gmail.com
(10) Port 587 is for users to send out emails on.Port 25 is for servers to relay messages to one another. That way ISPs’ can block outgoing SMTP on their network but still allow users to send email to any mail server through port 587.
(11) Now Run the project “send email in asp.net C#” using F5 key.
- write gmail username
- write gmail password
- write receiver’s address
- write Sender’s address(your gmail address)
- write Message Subject
- write Message body
- Click on the button to send email using c#.
If you see “message sent” text below then your message had successfully sent to the receiver and you successfully implemented code in asp.net for sending email.
(12) Some people do use Vb.net for developing their application. So below part of article explains “vb send email“ or “vba send email” functionality. Now, I am also posting code to send email in vb.net.
Namespaces are same for sending email in vb.net but you have to use “Imports” instead “using” to send email in vb.net.
Imports for vba or vb send email code
Send email vb.net or vb.net send email Code
Dim mm As MailMessage = New MailMessage() 'To initialize new message
mm.To.Add(New MailAddress(txtTo.Text)) 'For receiver's address
mm.From = New MailAddress(txtFrom.Text) 'For sender's address
mm.Subject = txtSub.Text 'For Subject of the mail
mm.Body = txtBody.Text 'For Body of the mail
mm.IsBodyHtml = True
Dim ss As New SmtpClient("smtp.gmail.com", 587)
ss.Credentials = New System.Net.NetworkCredential(txtUsr.Text, txtPass.Text)
ss.EnableSsl = True 'For Secure connection
ss.Send(mm) 'For sending message
lblReport.Text = "message sent" 'For delivery report
Catch ex As Exception
lblReport.Text = ex.Message
(13) Also you can send bulk mails using asp.net (C# and VB). Just little change is needed in above code to send bulk emails.
Hope to enjoyed learning “how to send automated email in asp.net and vb.net”.
send email in asp.net
vb.net send email
asp.net send email
vba send email
send email in asp.net c#
vb send email
how to send email in asp.net
send email vb.net