Exemplo n.º 1
0
        public void SendOneMailServerWithoutPasswordShouldWork()
        {
            InfosMailling info = new InfosMailling();
            info.toPeople.Add("*****@*****.**");
            info.subject = "subject";
            info.prio = MailPriority.High;
            info.ssl = false;
            info.modifyTimeOut(200000);
            MailLog log = new MailLog();

            Mailling.sendMail(info, log);
            Assert.AreEqual(1, _Server.ReceivedEmailCount);
        }
Exemplo n.º 2
0
        private static void Send(InfosMailling mail, MailLog log)
        {
            if (log != null)
            {
                log.DateSended = DateTime.UtcNow;
                log.Successful = true;
                log.To = String.Join(",", mail.toPeople.ToArray());
            }
            foreach (Attachment attach in mail.attachments)
                mail.MailMessage.Attachments.Add(attach);
            mail.MailMessage.Body = mail.body;
            mail.MailMessage.Subject = mail.subject;
            mail.MailMessage.IsBodyHtml = true;
            mail.MailMessage.Priority = mail.prio;
            mail.MailMessage.BodyEncoding = Encoding.UTF8;
            mail.MailMessage.SubjectEncoding = Encoding.UTF8;
            mail.smtpClient.EnableSsl = mail.ssl;
            try
            {
                mail.smtpClient.Send(mail.MailMessage);
                mail.MailMessage.Dispose();
            }
            catch (Exception e)
            {
                if (e is SmtpException || e is SmtpFailedRecipientsException)
                {
                    SmtpException ex = (SmtpException)e;

                    if (log == null)
                    {
                        if (Log.ExceptionLogger.IsErrorEnabled)
                            Log.ExceptionLogger.Error(e);
                        return;
                    }
                    log.Successful = false;
                    log.Reason = ex.Message;
                }
                else
                    throw;
            }
        }
Exemplo n.º 3
0
        public static void sendMail(InfosMailling mail, MailLog log)
        {
#if (PROD == true || DEV == true)
            foreach (String people in mail.toPeople)
                mail.MailMessage.To.Add(new MailAddress(people));
            Send(mail, log);
#endif
        }