Mail System API in create C#
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
namespace CationHRManagementSystem.WebAPI
{
public class SendMailAPI
{
public void SendEmail(string emailID,string mailSubject,string mailBody)
{
//MailMessage("From","To")
using (MailMessage mm = new MailMessage("cationtest@gmail.com", emailID))
{
mm.Subject = mailSubject;
mm.Body = mailBody;
//if (fuAttachment.HasFile)
//{
// string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);
// mm.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, FileName));
//}
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 465;
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("cationtest@gmail.com", "test_12345");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
}
}
}
}
Use of Mail API
using CationHRManagementSystem.WebAPI;
protected void sendMail()
{
SendMailAPI mailObj = new SendMailAPI();
mailObj.SendEmail(txtTo.Text, txtSubject.Text, txtBody.InnerText);
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
namespace CationHRManagementSystem.WebAPI
{
public class SendMailAPI
{
public void SendEmail(string emailID,string mailSubject,string mailBody)
{
//MailMessage("From","To")
using (MailMessage mm = new MailMessage("cationtest@gmail.com", emailID))
{
mm.Subject = mailSubject;
mm.Body = mailBody;
//if (fuAttachment.HasFile)
//{
// string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);
// mm.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, FileName));
//}
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 465;
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("cationtest@gmail.com", "test_12345");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
}
}
}
}
Use of Mail API
using CationHRManagementSystem.WebAPI;
protected void sendMail()
{
SendMailAPI mailObj = new SendMailAPI();
mailObj.SendEmail(txtTo.Text, txtSubject.Text, txtBody.InnerText);
}
No comments:
Post a Comment