1. Set-up SMTP E-mail Settings. You can either set-up under ASP.NET Configuration or manually set-up under web.config.
Option 1: ASP.NET Configuration
a. Under Menu, go to "Project" and click on "ASP.NET Configuration". Click the "Application" tab, and then click the "Configuration SMTP e-mail settings".
b. Set-up email settings. Add SMTP Settings depending on your mail server. the example below uses google smtp server for example purpose only.

Option 2: Manual Mail setting at web.config
a. Add the following tag under inside configuration tag of the web.config file.
2. Add code statement. Add the following code statement on the code behind. The statement below sends message to email.
using System.Net.Mail;
using System.IO;
protected void Page_Load(object sender, EventArgs e)
{
SendEmail();
}
private void SendEmail()
{
MailMessage message = new MailMessage();
message.From = new MailAddress("usernameFrom@gmail.com", "Name");
message.To.Add("usernameTo@gmail.com");
message.Subject = "Test Subject";
//if you want the message to show as HTML format
message.IsBodyHtml = true;
message.Body = "Your email message here.";
var client = new SmtpClient("smtp.gmail.com", 587);
//make sure its the same with SMTP Settings
client.Credentials = new System.Net.NetworkCredential("username@gmail.com", "MyPasswordHere");
client.Send(message);
}
3. Test and check sent email.
L.






0 comments:
Post a Comment