public void ShouldAddTheRecipientToTheRecipientsList() { EmailAgent agent = new EmailAgent("*****@*****.**", "mailname"); EmailMessage message = new EmailMessage("mailmessage"); Assert.AreEqual(0, message.Recipients.Length); message.AddRecipient(agent); Assert.AreEqual(1, message.Recipients.Length); Assert.AreEqual("mailname", message.Recipients[0].Name); }
public void SendTextAsHtml() { EmailMessage message = new EmailMessage("somemessage"); message.Sender = new EmailAgent("*****@*****.**", "somename"); message.Subject = "somesubject"; message.IsBodyHtml = false; message.Message = "<html><title>Text as HTML</title><body>sometext</body></html>"; message.AddRecipient(new EmailAgent("*****@*****.**", "Neylor Ohmaly")); Dictionary<string, string> options = new Dictionary<string, string>(); options["smtp-host"] = "smtp.acao.net.br"; options["smtp-port"] = "25"; SmtpMessenger messenger = new SmtpMessenger("somename", options); ResponseMessage response = messenger.Send(message); Assert.AreEqual(ResponseMessageType.ProcessedMessage, response.Type); }
static void SendHtml() { EmailMessage message = new EmailMessage("somemessage"); message.Sender = new EmailAgent("*****@*****.**", "Comunicacao Acao"); message.Subject = "Pesquisa Perfil"; message.IsBodyHtml = true; message.Message = @"<html> <head> <title>Pesquisa Perfil Acao</title> </head> <body> <a href=""$link$""> <img alt=""Pesquisa Perfil Acao"" src=""http://192.168.203.8:8080/images/pesquisa_adm.jpg""/> </a> </body> </html>"; message.AddRecipient(new EmailAgent("*****@*****.**", "Comunicacao")); Dictionary<string, string> options = new Dictionary<string, string>(); options["smtp-host"] = "smtp.acao.net.br"; options["smtp-port"] = "25"; SmtpMessenger messenger = new SmtpMessenger("somename", options); ResponseMessage response = messenger.Send(message); }
public void TheDefaultBodyShouldBeNonHtml() { string mail_message = "mailmessage"; EmailMessage message = new EmailMessage(mail_message); Assert.AreEqual(false, message.IsBodyHtml); }
public void ShouldReturnAnEmptyArrayWhenNoRecipientsWasSpecified() { string mail_message = "mailmessage"; EmailMessage message = new EmailMessage(mail_message); Assert.AreEqual(0, message.Recipients.Length); }
public void ShouldReturnTheSpecifiedMessage() { string mail_message = "mailmessage"; EmailMessage message = new EmailMessage(mail_message); Assert.AreEqual(mail_message, message.Message); }
/// <summary> /// Sends the specified <paramref name="message"/> to an SMTP server for /// delivery. /// </summary> /// <param name="message">The message to send.</param> /// <returns>A <see cref="ResponseMessage"/> object containing the message /// that the server sent in response.</returns> /// <exception cref="ArgumentNullException"><paramref name="message"/> is a /// null reference.</exception> /// <remarks> /// If the message is successfully sent the Send method will returns a /// processed <see cref="ResponseMessage"/> as response. /// <para> /// If a required information is missing this method will returns an /// error<see cref="ResponseMessage"/> containing the text describing the /// cause of the error as response. /// </para> /// <para> /// This method uses the <see cref="SmtpClient"/> class to delivery the /// <paramref name="message"/> to the SMTP server and rely on the behavior /// of this class. The exceptions that are thrown by the /// <see cref="SmtpClient"/> class will not be caught by this method and /// the exception will be propagated to the caller. /// </para> /// </remarks> /// <seealso cref="SmtpClient"/> public IMessage Send(EmailMessage message) { if (message == null) throw new ArgumentNullException("messsage"); ResponseMessage response; if (!ValidateMessage(message, out response)) return response; MailMessage mail_message = new MailMessage(); mail_message.From = new MailAddress(message.Sender.Address, message.Sender.Name); mail_message.IsBodyHtml = message.IsBodyHtml; mail_message.Subject = message.Subject; mail_message.Body = message.Message; MailAddressCollection addresses = mail_message.To; for (int i = 0, j = message.Recipients.Length; i < j; i++) { IAgent recipient = message.Recipients[i]; if (recipient.Address != null && recipient.Name != null) addresses.Add(new MailAddress(recipient.Address, recipient.Name)); } smtp_client_.Send(mail_message); return new ResponseMessage(ResponseMessageType.ProcessedMessage); }