//IF You don't have SmtpClient Url and port No then you must give your gmail id and //paswword.
SendHtmlFormattedEmail("Your Subject", "From GMAIL MailID", "GMAIL ID Pwd", "To MailID", "Bcc MailID", "CC MailID", FileUploadControlID);
public void SendHtmlFormattedEmail(string objSubject,string objFromMailID, string objPwd, string objToMailID, string objBccMailID, string objCCMailID, FileUpload fuAttachment)
{
try
{
MailMessage objMailMsg;
objMailMsg = new MailMessage();
objMailMsg.From = new MailAddress(objFromMailID);
objMailMsg.Bcc.Add(objBccMailID);
objMailMsg.Bcc.Add(objCCMailID);
objMailMsg.To.Add(objToMailID);
objMailMsg.Subject = objSubject;
objMailMsg.Body = FunForHtmlMailFormat("YOUR PRODUCT_ID", "YOUR PRODUCT_CODE");
if (fuAttachment.HasFile)
{
string stringFileName = System.IO.Path.GetFileName(fuAttachment.PostedFile.FileName);
objMailMsg.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, stringFileName));
}
#region Have_SmtpClient
////If you did have SmtpClient Url and port means you will used below code else command below //code enable #region Not_Have_SmtpClient code
//SmtpClient objSmtpClient = new SmtpClient(objAutomailURL, Convert.ToInt32(objAutomailPort));
//objSmtpClient.Host = objAutomailURL;
//objSmtpClient.Port = Convert.ToInt32(objAutomailPort);
//objSmtpClient.UseDefaultCredentials = false;
//objSmtpClient.Send(objMailMsg);
//objSmtpClient.Dispose();
#endregion
#region Not_Have_SmtpClient
////If you did not have SmtpClient Url and port means you will used below code else command below code enable #region Have_SmtpClient code
SmtpClient objSmtpClient = new SmtpClient("smtp.gmail.com");
objSmtpClient.Port = 587;
objSmtpClient.EnableSsl = true;
objSmtpClient.UseDefaultCredentials = false;
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
objSmtpClient.Credentials = new System.Net.NetworkCredential(objFromMailID, objPwd);
objSmtpClient.Send(objMailMsg);
objSmtpClient.Dispose();
#endregion
}
catch (Exception ex)
{
throw ex;
}
}
private static string FunForHtmlMailFormat(string objID, string objName)
{
return " < html >< body >< div style = 'font-family:Calibri; font-size: 14px; width: 100%!important; min-height: 100%; line-height: 1.6em; background-color: #f6f6f6; margin: 0' >< table style = 'font-family: Calibri; font-size: 14px; width: 100%; background-color: #f6f6f6; margin: 0' >< tbody >< tr style = 'font-family: Calibri; font-size: 14px; margin: 0' >< td style = 'font-family: Calibri; font-size: 14px; vertical-align: top; margin: 0' ></ td >< td style = 'width: 600px; font-family: Calibri; font-size: 14px; vertical-align: top; display: block!important; max-width: 600px!important; clear: both!important; margin: 0 auto' >< div style = 'font-family: Calibri; font-size: 14px; max-width: 600px; display: block; margin: 0 auto; padding: 20px' >< table style = 'width: 100%; font-family: Calibri; font-size: 14px; border-radius: 3px; background-color: #fff; margin: 0; border: 1px solid #e9e9e9' >< tbody >< tr style = 'font-family: Calibri; font-size: 14px; margin: 0' >< td style = 'font-family: Calibri; font-size: 16px; vertical-align: top; color: #fff; font-weight: 500; text-align: left; border-radius: 3px 3px 0 0; background-color: #00ACAC; margin: 0; padding: 20px' >< label style = 'font-size:36px;font-family:Impact;color:black;' > YOUR APPLICATION NAME</ label ></ td ></ tr >< tr style = 'font-family: Calibri; font-size: 14px; margin: 0' >< td style = 'font-family: Calibri; font-size: 14px; vertical-align: top; margin: 0; padding: 20px' >< table style = 'width: 100%; font-family: Calibri; font-size: 14px; margin: 0' >< tbody >< tr style = 'font-family: Calibri; font-size: 14px; margin: 0' >< td style = 'font-family: Calibri; font-size: 18px; vertical-align: top; margin: 0; padding: 0 0 20px' > Dear All,</ td ></ tr >< tr style = 'font-family: Calibri; font-size: 14px; margin: 0' >< td style = 'font-family: Calibri; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px' >YOUR DESCRIPTION < table style = 'font-size: 12px; width: 480px; text-align: left; border-collapse: collapse; margin: 20px;'summary = 'Meeting Results' >< tbody >< tr style = 'display: table-row;' >< td style = 'color: #669; border: 1px solid #ddd; padding:5px;font-weight:bold;' > Product Id </ td >< td style = 'color: #669; border: 1px solid #ddd; padding:5px;' > " + objID + " </ td ></ tr >< tr >< td style = 'color: #669; border: 1px solid #ddd; padding:5px;font-weight:bold;' > Product Name </ td >< td style = 'color: #669; border: 1px solid #ddd; padding:5px;' > " + objName + " </ td ></ tr ></ tbody ></ table ></ td ></ tr >< tr style = 'font-family: Calibri; font-size: 14px; margin: 0' >< td style = 'font-family: Calibri; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px' > Thanking You,< br />< i >< span > YOUR SIGNATURE </ span > </ i >< br />< br /> Please do not reply to this mail - id, It is an automated mail.</ td ></ tr >< tr style = 'font-family: Calibri; font-size: 14px; margin: 0' >< td style = 'font-family: Calibri; font-size: 12px; line-height: 16px; color: #aaa; vertical-align: top; margin: 0; padding: 20px 0 20px; border-top: 1px #ccc solid; text-align: center;color:#008A8A;' > All rights reserved © YOUR COPY RIGHTS DETAILS 2016. </ td ></ tr ></ tbody ></ table ></ td ></ tr ></ tbody ></ table ></ div ></ td >< td style = 'font-family: Calibri; font-size: 14px; vertical-align: top; margin: 0' ></ td ></ tr ></ tbody ></ table ></ div ></ body ></ html >";
}