public static bool enviarEmail(string sendFrom, string sendTo, List<string> destinatarios, string emailOrigem, 
            string Password, string Assunto, string corpoMensagem, bool isHtml,
            EmailConfigs configEmail)
        {
            try
            {
                MailMessage mail = new MailMessage();

                mail.To.Add(sendTo);

                foreach (var destinatario in destinatarios)
                    mail.Bcc.Add(destinatario);

                mail.From = new MailAddress(sendFrom);
                mail.Subject = Assunto;

                mail.Body = corpoMensagem;
                mail.IsBodyHtml = isHtml;

                SmtpClient smtp = new SmtpClient();

                smtp.Host = configEmail.SmtpHost;
                smtp.EnableSsl = configEmail.UsaSsl;

                if (configEmail.Porta != null)
                    smtp.Port = configEmail.Porta.Value;

                //smtp.UseDefaultCredentials = false;

                if (configEmail.UsaAutenticacaoPop)
                    smtp.Credentials = new System.Net.NetworkCredential(emailOrigem, Password);

                smtp.Timeout = 10000;
                smtp.Send(mail);

                return true;
            }
            catch
            {
                return false;
            }
        }
コード例 #2
0
 /// <summary>
 /// Create a new EmailConfigs object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="smtpHost">Initial value of the SmtpHost property.</param>
 /// <param name="pop3Host">Initial value of the Pop3Host property.</param>
 /// <param name="usaSsl">Initial value of the UsaSsl property.</param>
 /// <param name="usaAutenticacaoPop">Initial value of the UsaAutenticacaoPop property.</param>
 /// <param name="idEstabelecimento">Initial value of the IdEstabelecimento property.</param>
 public static EmailConfigs CreateEmailConfigs(global::System.Int32 id, global::System.String smtpHost, global::System.String pop3Host, global::System.Boolean usaSsl, global::System.Boolean usaAutenticacaoPop, global::System.Int32 idEstabelecimento)
 {
     EmailConfigs emailConfigs = new EmailConfigs();
     emailConfigs.Id = id;
     emailConfigs.SmtpHost = smtpHost;
     emailConfigs.Pop3Host = pop3Host;
     emailConfigs.UsaSsl = usaSsl;
     emailConfigs.UsaAutenticacaoPop = usaAutenticacaoPop;
     emailConfigs.IdEstabelecimento = idEstabelecimento;
     return emailConfigs;
 }
コード例 #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the EmailConfigs EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToEmailConfigs(EmailConfigs emailConfigs)
 {
     base.AddObject("EmailConfigs", emailConfigs);
 }