static string displayName = System.Configuration.ConfigurationManager.AppSettings["DisplayName"];
#region send mail without attchment
/// <summary> send mail without attchment
/// <para>EmailMessageID</para> pass to emailMessage id
/// <para>MailSubject</para> pass mail subject name
/// <para>MailBody</para> pass Mail decription
/// <para>cc</para> pass cc mail id
/// <para>bc</para> pass bc mail id
/// <para>FromMail</para> pass Network Credential from emailMessage id (user name)
/// <para>password</para> pass Network Credential Password (user password)
/// <para>host</para> pass Network Credential host for send mailMessage
/// <para>port</para> pass Network Credential port for send mailMessage
/// <DevelopedBy>Neelkamal bansal</DevelopedBy>
/// </summary>
public static void SendMail(string emailMessageId, string mailMessageSubject, string mailMessageBody, string cC, string bC, string fromMail, string password, string host, int port)
{
try
{
string username = Convert.ToString(ConfigurationManager.AppSettings["Username"]);
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add(emailMessageId);
if (!string.IsNullOrEmpty(cC))
{
mailMessage.CC.Add(cC);
}
if (!string.IsNullOrEmpty(bC))
{
mailMessage.Bcc.Add(bC);
}
mailMessage.From = new MailAddress(fromMail, displayName);
mailMessage.IsBodyHtml = true;
mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
mailMessage.Subject = mailMessageSubject;
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
mailMessage.Body = mailMessageBody;
SmtpClient smtpClient = new SmtpClient();
smtpClient.Port = port;
smtpClient.Host = host;
smtpClient.EnableSsl = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(username, password);
smtpClient.Send(mailMessage);
smtpClient.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}
public static void ForgotPassSendMail(string emailMessageId, string mailMessageSubject, string mailMessageBody, string cC, string bC, string fromMail, string password, string host, int port)
{
try
{
string username = Convert.ToString(ConfigurationManager.AppSettings["FUsername"]);
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add(emailMessageId);
if (!string.IsNullOrEmpty(cC))
{
mailMessage.CC.Add(cC);
}
if (!string.IsNullOrEmpty(bC))
{
mailMessage.Bcc.Add(bC);
}
mailMessage.From = new MailAddress(fromMail, displayName);
mailMessage.Subject = mailMessageSubject;
mailMessage.IsBodyHtml = true;
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
mailMessage.Body = mailMessageBody;
mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
SmtpClient smtpClient = new SmtpClient();
smtpClient.Port = port;
smtpClient.Host = host;
smtpClient.EnableSsl = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(username, password);
smtpClient.Send(mailMessage);
smtpClient.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region send mail with single attchment
/// <summary> send mailMessage with single attchment
/// <para>EmailMessageID</para> pass to emailMessage id
/// <para>MailSubject</para> pass mailMessage subject name
/// <para>MailBody</para> pass Mail decription
/// <para>cc</para> pass cc mailMessage id
/// <para>bc</para> pass bc mailMessage id
/// <para>FromMail</para> pass Network Credential from emailMessage id (user name)
/// <para>password</para> pass Network Credential Password (user password)
/// <para>host</para> pass Network Credential host for send mailMessage
/// <para>port</para> pass Network Credential port for send mailMessage
/// <para>attachmentfile</para> pass attchment (ex- doc, image, pdf and any other)
/// <DevelopedBy>Neelkamal bansal</DevelopedBy>
/// </summary>
public static void SendMail(string emailMessageId, string mailMessageSubject, string mailMessageBody, string cC, string bC, string fromMail, string password, string host, int port, byte[] attachmentFile, string filename)
{
try
{
MailMessage mailMessage = new MailMessage();
string username = Convert.ToString(ConfigurationManager.AppSettings["Username"]);
mailMessage.To.Add(emailMessageId);
if (!string.IsNullOrEmpty(cC))
{
mailMessage.CC.Add(cC);
}
if (!string.IsNullOrEmpty(bC))
{
mailMessage.Bcc.Add(bC);
}
mailMessage.From = new MailAddress(fromMail, displayName);
mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
mailMessage.Subject = mailMessageSubject;
mailMessage.IsBodyHtml = true;
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
mailMessage.Body = mailMessageBody;
// Attachment attachment = new Attachment(attachmentFile, MediaTypeNames.Application.Octet);
Attachment attachment = new Attachment(new MemoryStream(attachmentFile), filename);
mailMessage.Attachments.Add(attachment);
SmtpClient smtpClient = new SmtpClient();
smtpClient.Port = port;
smtpClient.Host = host;
smtpClient.EnableSsl = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
// smtpClient.ServicePoint.MaxIdleTime = 1;
smtpClient.Credentials = new NetworkCredential(username, password);
smtpClient.Send(mailMessage);
smtpClient.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region send mail with multiple attchment
/// <summary> send mailMessage with multiple attchment
/// <para>EmailMessageID</para> pass to emailMessage id
/// <para>MailSubject</para> pass mailMessage subject name
/// <para>MailBody</para> pass Mail decription
/// <para>cc</para> pass cc mailMessage id
/// <para>bc</para> pass bc mailMessage id
/// <para>FromMail</para> pass Network Credential from emailMessage id (user name)
/// <para>password</para> pass Network Credential Password (user password)
/// <para>host</para> pass Network Credential host for send mailMessage
/// <para>port</para> pass Network Credential port for send mailMessage
/// <para>attachmentfile</para> pass multiple attchment in array (ex- doc, image, pdf and any other)
/// <DevelopedBy>Neelkamal bansal</DevelopedBy>
/// </summary>
public static void SendMail(string emailMessageIDd, string mailMessageSubject, string mailMessageBody, string cC, string bC, string fromMail, string password, string host, int port, string[] attachmentFile)
{
try
{
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add(emailMessageIDd);
if (!string.IsNullOrEmpty(cC))
{
mailMessage.CC.Add(cC);
}
if (!string.IsNullOrEmpty(bC))
{
mailMessage.Bcc.Add(bC);
}
mailMessage.From = new MailAddress(fromMail, displayName);
mailMessage.Subject = mailMessageSubject;
mailMessage.IsBodyHtml = true;
mailMessage.Body = mailMessageBody;
if (attachmentFile.Length > 0)
{
for (int i = 0; i < attachmentFile.Length; i++)
{
Attachment attachment = new Attachment(attachmentFile[i], MediaTypeNames.Application.Octet);
ContentDisposition disposition = attachment.ContentDisposition;
disposition.CreationDate = File.GetCreationTime(attachmentFile[i]);
disposition.ModificationDate = File.GetLastWriteTime(attachmentFile[i]);
disposition.ReadDate = File.GetLastAccessTime(attachmentFile[i]);
disposition.FileName = Path.GetFileName(attachmentFile[i]);
disposition.Size = new FileInfo(attachmentFile[i]).Length;
disposition.DispositionType = DispositionTypeNames.Attachment;
mailMessage.Attachments.Add(attachment);
}
}
SmtpClient smtpClient = new SmtpClient();
smtpClient.Port = port;
smtpClient.Host = host;
smtpClient.EnableSsl = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(fromMail, password);
smtpClient.Send(mailMessage);
smtpClient.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
<appSettings>
<add key="DisplayName" value="تحدي القراءة العربي"/>
<add key="EmailUname" value="test_flexsin@seologistics.com"/>
<add key="Username" value="test_flexsin@seologistics.com"/>
<add key="EmailPassword" value="Ybv0B'mJKLIU*%$"/>
<add key="Host" value="mail.seologistics.com"/>
<add key="Port" value="25"/>
<add key="CC" value=""/>
<add key="BC" value="neelkamal_bansal@seologistics.com"/>
<add key="FDisplayName" value="Arab Reading Challenge"/>
<add key="FEmailUname" value="test_flexsin@seologistics.com"/>
<add key="FUsername" value="test_flexsin@seologistics.com"/>
<add key="FEmailPassword" value="Ybv0B'mJKLIU*%$"/>
<add key="FHost" value="mail.seologistics.com"/>
<add key="FPort" value="25"/>
<add key="FCC" value=""/>
<add key="FBC" value="avdhesh_kumar12@seologistics.com"/>
<add key="UserNameLength" value="8"/>
<add key="pagingsize" value="25"/>
<add key="PasswordLength" value="6"/>
<add key="PageUrl" value="http://localhost:49787/index.aspx"/>
<add key="BackupFolder" value="C:/ARC/"/>
<add key="IndexredirectUrl" value="http://localhost:49787/index.aspx"/>
</appSettings>
#region send mail without attchment
/// <summary> send mail without attchment
/// <para>EmailMessageID</para> pass to emailMessage id
/// <para>MailSubject</para> pass mail subject name
/// <para>MailBody</para> pass Mail decription
/// <para>cc</para> pass cc mail id
/// <para>bc</para> pass bc mail id
/// <para>FromMail</para> pass Network Credential from emailMessage id (user name)
/// <para>password</para> pass Network Credential Password (user password)
/// <para>host</para> pass Network Credential host for send mailMessage
/// <para>port</para> pass Network Credential port for send mailMessage
/// <DevelopedBy>Neelkamal bansal</DevelopedBy>
/// </summary>
public static void SendMail(string emailMessageId, string mailMessageSubject, string mailMessageBody, string cC, string bC, string fromMail, string password, string host, int port)
{
try
{
string username = Convert.ToString(ConfigurationManager.AppSettings["Username"]);
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add(emailMessageId);
if (!string.IsNullOrEmpty(cC))
{
mailMessage.CC.Add(cC);
}
if (!string.IsNullOrEmpty(bC))
{
mailMessage.Bcc.Add(bC);
}
mailMessage.From = new MailAddress(fromMail, displayName);
mailMessage.IsBodyHtml = true;
mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
mailMessage.Subject = mailMessageSubject;
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
mailMessage.Body = mailMessageBody;
SmtpClient smtpClient = new SmtpClient();
smtpClient.Port = port;
smtpClient.Host = host;
smtpClient.EnableSsl = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(username, password);
smtpClient.Send(mailMessage);
smtpClient.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}
public static void ForgotPassSendMail(string emailMessageId, string mailMessageSubject, string mailMessageBody, string cC, string bC, string fromMail, string password, string host, int port)
{
try
{
string username = Convert.ToString(ConfigurationManager.AppSettings["FUsername"]);
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add(emailMessageId);
if (!string.IsNullOrEmpty(cC))
{
mailMessage.CC.Add(cC);
}
if (!string.IsNullOrEmpty(bC))
{
mailMessage.Bcc.Add(bC);
}
mailMessage.From = new MailAddress(fromMail, displayName);
mailMessage.Subject = mailMessageSubject;
mailMessage.IsBodyHtml = true;
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
mailMessage.Body = mailMessageBody;
mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
SmtpClient smtpClient = new SmtpClient();
smtpClient.Port = port;
smtpClient.Host = host;
smtpClient.EnableSsl = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(username, password);
smtpClient.Send(mailMessage);
smtpClient.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region send mail with single attchment
/// <summary> send mailMessage with single attchment
/// <para>EmailMessageID</para> pass to emailMessage id
/// <para>MailSubject</para> pass mailMessage subject name
/// <para>MailBody</para> pass Mail decription
/// <para>cc</para> pass cc mailMessage id
/// <para>bc</para> pass bc mailMessage id
/// <para>FromMail</para> pass Network Credential from emailMessage id (user name)
/// <para>password</para> pass Network Credential Password (user password)
/// <para>host</para> pass Network Credential host for send mailMessage
/// <para>port</para> pass Network Credential port for send mailMessage
/// <para>attachmentfile</para> pass attchment (ex- doc, image, pdf and any other)
/// <DevelopedBy>Neelkamal bansal</DevelopedBy>
/// </summary>
public static void SendMail(string emailMessageId, string mailMessageSubject, string mailMessageBody, string cC, string bC, string fromMail, string password, string host, int port, byte[] attachmentFile, string filename)
{
try
{
MailMessage mailMessage = new MailMessage();
string username = Convert.ToString(ConfigurationManager.AppSettings["Username"]);
mailMessage.To.Add(emailMessageId);
if (!string.IsNullOrEmpty(cC))
{
mailMessage.CC.Add(cC);
}
if (!string.IsNullOrEmpty(bC))
{
mailMessage.Bcc.Add(bC);
}
mailMessage.From = new MailAddress(fromMail, displayName);
mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
mailMessage.Subject = mailMessageSubject;
mailMessage.IsBodyHtml = true;
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
mailMessage.Body = mailMessageBody;
// Attachment attachment = new Attachment(attachmentFile, MediaTypeNames.Application.Octet);
Attachment attachment = new Attachment(new MemoryStream(attachmentFile), filename);
mailMessage.Attachments.Add(attachment);
SmtpClient smtpClient = new SmtpClient();
smtpClient.Port = port;
smtpClient.Host = host;
smtpClient.EnableSsl = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
// smtpClient.ServicePoint.MaxIdleTime = 1;
smtpClient.Credentials = new NetworkCredential(username, password);
smtpClient.Send(mailMessage);
smtpClient.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region send mail with multiple attchment
/// <summary> send mailMessage with multiple attchment
/// <para>EmailMessageID</para> pass to emailMessage id
/// <para>MailSubject</para> pass mailMessage subject name
/// <para>MailBody</para> pass Mail decription
/// <para>cc</para> pass cc mailMessage id
/// <para>bc</para> pass bc mailMessage id
/// <para>FromMail</para> pass Network Credential from emailMessage id (user name)
/// <para>password</para> pass Network Credential Password (user password)
/// <para>host</para> pass Network Credential host for send mailMessage
/// <para>port</para> pass Network Credential port for send mailMessage
/// <para>attachmentfile</para> pass multiple attchment in array (ex- doc, image, pdf and any other)
/// <DevelopedBy>Neelkamal bansal</DevelopedBy>
/// </summary>
public static void SendMail(string emailMessageIDd, string mailMessageSubject, string mailMessageBody, string cC, string bC, string fromMail, string password, string host, int port, string[] attachmentFile)
{
try
{
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add(emailMessageIDd);
if (!string.IsNullOrEmpty(cC))
{
mailMessage.CC.Add(cC);
}
if (!string.IsNullOrEmpty(bC))
{
mailMessage.Bcc.Add(bC);
}
mailMessage.From = new MailAddress(fromMail, displayName);
mailMessage.Subject = mailMessageSubject;
mailMessage.IsBodyHtml = true;
mailMessage.Body = mailMessageBody;
if (attachmentFile.Length > 0)
{
for (int i = 0; i < attachmentFile.Length; i++)
{
Attachment attachment = new Attachment(attachmentFile[i], MediaTypeNames.Application.Octet);
ContentDisposition disposition = attachment.ContentDisposition;
disposition.CreationDate = File.GetCreationTime(attachmentFile[i]);
disposition.ModificationDate = File.GetLastWriteTime(attachmentFile[i]);
disposition.ReadDate = File.GetLastAccessTime(attachmentFile[i]);
disposition.FileName = Path.GetFileName(attachmentFile[i]);
disposition.Size = new FileInfo(attachmentFile[i]).Length;
disposition.DispositionType = DispositionTypeNames.Attachment;
mailMessage.Attachments.Add(attachment);
}
}
SmtpClient smtpClient = new SmtpClient();
smtpClient.Port = port;
smtpClient.Host = host;
smtpClient.EnableSsl = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(fromMail, password);
smtpClient.Send(mailMessage);
smtpClient.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
<appSettings>
<add key="DisplayName" value="تحدي القراءة العربي"/>
<add key="EmailUname" value="test_flexsin@seologistics.com"/>
<add key="Username" value="test_flexsin@seologistics.com"/>
<add key="EmailPassword" value="Ybv0B'mJKLIU*%$"/>
<add key="Host" value="mail.seologistics.com"/>
<add key="Port" value="25"/>
<add key="CC" value=""/>
<add key="BC" value="neelkamal_bansal@seologistics.com"/>
<add key="FDisplayName" value="Arab Reading Challenge"/>
<add key="FEmailUname" value="test_flexsin@seologistics.com"/>
<add key="FUsername" value="test_flexsin@seologistics.com"/>
<add key="FEmailPassword" value="Ybv0B'mJKLIU*%$"/>
<add key="FHost" value="mail.seologistics.com"/>
<add key="FPort" value="25"/>
<add key="FCC" value=""/>
<add key="FBC" value="avdhesh_kumar12@seologistics.com"/>
<add key="UserNameLength" value="8"/>
<add key="pagingsize" value="25"/>
<add key="PasswordLength" value="6"/>
<add key="PageUrl" value="http://localhost:49787/index.aspx"/>
<add key="BackupFolder" value="C:/ARC/"/>
<add key="IndexredirectUrl" value="http://localhost:49787/index.aspx"/>
</appSettings>
No comments:
Post a Comment