How to send E-mail from Asp.net application
There are so many way to send E-mail from ASP.NET webpage to any given particular email address, but most common way and most frequently used way to sent email from asp.net webpage by using SMTP. So here below Article Described you the Steps to send an Email from your ASP.NET webpage
There is a simply 3 Step process to sent an email from asp.net webpage to the Given E-mail ID. All 3 step to sent an email from webpage to Email id is given below
Step 1 : Configure your web.config file in Mailsettings Section
host="smtp.gmail.com"
port="587"
userName=""
password=""
Step-2 Define below Namespace in your code behind file
using System.Net;
using System.Net.Mail;
Step- 3 On button Click Right below code to sent an email
protected void btnSend_Click(object sender, EventArgs e)
{
Try
{
string toEmailID = "xxX@gmail.com";
string mailId = "xyz@gmail.com";
string bodyMsg = "Test Email";
string subject = "TEST";
MailMessage mail = new MailMessage();
mail.To.Add(toEmailID);
mail.From = new MailAddress(mailId);
mail.Subject = subject;
mail.Body = bodyMsg;
mail.Cc = "ABC@yahoo.com";
mail.Bcc = "ABC@yahoo.com";
mail.IsBodyHtml = true;
//Attach file using FileUpload Control and put the file in memory stream
if (FileUpload1.HasFile)
{
mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream , FileUpload1.FileName));
}
SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = true;
smtp.Send(mail);
lblmsg.Text = "Your E-mail is sent sucessfully";
}
Catch(Exception ex)
{
Throw ex;
}
finally {}
}
Few Comments:
You can add CC Address, BCC Address, Attachment, Attachment as zip etc.,.
Then it will include complete code with all the mail options.
The Basic functionality of sending mail looks very Good and useful to the beginers