-
Create a library project named it EmailManager
-
Write this code to the class
-
public class
EmailSender
-
{
-
public bool
EmailSend(MailMessage msg)
-
{
-
SmtpClient smtp = new
SmtpClient();
-
-
smtp.Host =
"smtp.gmail.com";
-
smtp.Credentials = new System.Net.NetworkCredential("emailid@apsissolutions.com", "password");
-
smtp.Port =
587;
-
smtp.EnableSsl = true;
-
try
-
{
-
smtp.Send(msg);
-
return true;
-
}
-
catch
-
{
-
return false;
-
}
-
-
}
-
-
}
-Now build the project. A dll file created. Right click on
the project select open project in windows explorer.
-Now we will send mail with this dll file we created.create a
asp.net project add Reference -> select the dll file.
public EmailSender emailObj = null;
protected void Page_Load(object
sender, EventArgs e)
{
emailObj = new
EmailSender();
}
protected void Button1_Click(object
sender, EventArgs e)
{
string
to = "email@host.com";
string
subject = "Subject Goes Here";
//string
mailBody = "This E-mail From Egy Mall </br> The User Code For Your
Employee Is :";
MailMessage
msg = new MailMessage();
msg.To.Add(to);
msg.CC.Add("email@host.com");
msg.CC.Add("email@host.com");
msg.From = new
MailAddress(to);
msg.Subject = subject;
msg.Body = "<html><body>";
msg.Body += "<p>
This is an automatic email ";
msg.Body += "indicating
that we have received your request for ";
msg.Body += "more
information about really cool web designs.</p>";
msg.Body += "Someone
will be contacting you shortly.</p>";
msg.Body += "<p> ";
msg.Body += "<p>Website
Design Guide<br>";
msg.Body += "http://www.website-designguide.com<br>";
msg.Body += "<p> ";
msg.Body += "</body></html>";
/**
* StringBuilder body = new
StringBuilder();
body.Append("<html><body><table><tr><td>Name</td>");
body.Append(txtSubject.Text);
body.Append("</td></tr><tr><td>Contact" + txtSubject.Text);
body.Append("</td><tr></table></body></html>");
MailMessage mail = new
MailMessage();
mail.To.Add(toEmailAddress);
mail.From = new
MailAddress(GmailId);
mail.Subject = txtSubject.Text;
mail.Body = body.ToString();
mail.IsBodyHtml = true;
*/
//msg.Body =
mailBody;
msg.IsBodyHtml = true;
emailObj.EmailSend(msg);
}
Write this code in an button click event.
No comments:
Post a Comment