Untitled
unknown
plain_text
a year ago
3.0 kB
7
Indexable
public void FrmcEnviarEmail(DTO_Usuario_Email email, DTO_Email_ead dTO_Email_ead, string in_treinamento, string in_producao)
{
using (MailMessage mailMessage = new MailMessage())
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
if ((!string.IsNullOrEmpty(email.email_gd)) && (dTO_Email_ead.in_superior.Equals("S")))
mailMessage.Bcc.Add(new MailAddress(email.email_gd));
if (!string.IsNullOrEmpty(dTO_Email_ead.email_copia))
{
string[] eCopia = dTO_Email_ead.email_copia.Split(';');
foreach (string eml in eCopia)
{
mailMessage.Bcc.Add(new MailAddress(eml));
}
}
else
{
if (in_treinamento.Equals("S"))
mailMessage.Bcc.Add(new MailAddress(ConfigurationManager.AppSettings["email_treinamento"]));
if (in_producao.Equals("S"))
mailMessage.Bcc.Add(new MailAddress(ConfigurationManager.AppSettings["email_producao"]));
}
mailMessage.From = !string.IsNullOrEmpty(dTO_Email_ead.email_from) ? new MailAddress(dTO_Email_ead.email_from) : new MailAddress(ConfigurationManager.AppSettings["Remetente"]);
mailMessage.Subject = !string.IsNullOrEmpty(dTO_Email_ead.email_subject) ? dTO_Email_ead.email_subject : "GSK - Uniccampo Digital";
string body = dTO_Email_ead.email_body;
body = body.Replace("{nome_rep}", email.nome_rep);
body = body.Replace("{CaminhoLogo}", ResgataIcone("logo-gsk.gif"));
mailMessage.Body = body;
mailMessage.IsBodyHtml = true;
if ((!string.IsNullOrEmpty(email.email_rep)) && (dTO_Email_ead.in_rep.Equals("S")))
mailMessage.To.Add(new MailAddress(email.email_rep));
SmtpClient smtp = new SmtpClient();
smtp.Host = !string.IsNullOrEmpty(dTO_Email_ead.smtp_host) ? dTO_Email_ead.smtp_host : ConfigurationManager.AppSettings["smtp_host"];
bool enableSsl = dTO_Email_ead.enable_ssl.Equals("S") ? true : false;
smtp.EnableSsl = !string.IsNullOrEmpty(dTO_Email_ead.enable_ssl) ? enableSsl : Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSsl"]);
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = !string.IsNullOrEmpty(dTO_Email_ead.smtp_user) ? dTO_Email_ead.smtp_user : ConfigurationManager.AppSettings["smtp_user"];
NetworkCred.Password = !string.IsNullOrEmpty(dTO_Email_ead.smtp_pass) ? dTO_Email_ead.smtp_pass : ConfigurationManager.AppSettings["smtp_pass"];
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = !string.IsNullOrEmpty(dTO_Email_ead.smtp_port) ? int.Parse(dTO_Email_ead.smtp_port) : int.Parse(ConfigurationManager.AppSettings["smtp_port"]);
smtp.Send(mailMessage);
}
}Editor is loading...
Leave a Comment