public EmailNotificatorTests(ITestOutputHelper output) { _output = output; var senderAddress = "*****@*****.**"; var senderName = "notif-test"; var mailhogSmtpServerConfig = new SmtpServerConfig() { Host = "localhost", Port = 25, SenderName = senderName, SenderAddress = senderAddress }; var mailSettingsConfig = new MailSettingsConfig() { Smtp = new MailSettingsConfig.SmtpConfig() { Servers = new List <SmtpServerConfig>() { mailhogSmtpServerConfig } } }; var toList = new List <string>(); var subject = "Test subject"; var body = "Test body"; _emailMessage = new EmailMessage(toList, subject, body); var smtpClientFactory = new SmtpClientWithoutSslFactory(); var mailMessageFactory = new MailMessageFactory(); _notificator = new EmailNotificator(smtpClientFactory, mailSettingsConfig, mailMessageFactory); }
public static void sendEmailByExternalServer(List <string> emailsTo, string subject, string body, SmtpServers server) { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpServerConfig(server); mail.From = new MailAddress("*****@*****.**", "خبرنامه تازه یاب"); mail.Body = body; mail.Subject = subject; mail.IsBodyHtml = true; foreach (var email in emailsTo) { if (ValidEmail(email)) { mail.Bcc.Add(email); } } try { SmtpServer.Send(mail); GeneralLogs.WriteLogInDB(">OK sended Email to " + emailsTo.Count); } catch (Exception ex) { GeneralLogs.WriteLogInDB(">Error sending email to " + emailsTo.Count + ex.Message); } }
public bool Send(Push item) { if (item == null) { throw new ArgumentNullException("item"); } List <Commit> commits = item.Commits; if (commits == null || commits.Count == 0) { Log(LogSeverity.Info, "Push has no commits. Not sending mails."); return(false); } SmtpServerConfig smtpConfig = Config.Instance.SmtpServer; MailMessage message = null; try { foreach (Commit c in commits) { if (!c.FetchDiff(item)) { return(false); } } var template = GetMailTemplate <Push> (item.CHAuthID); message = template.ComposeMail(item); if (message == null) { Log(LogSeverity.Error, "No mail message composed."); return(false); } var smtp = new SmtpClient(); smtp.Host = smtpConfig.Host; smtp.Port = smtpConfig.Port; smtp.EnableSsl = smtpConfig.EnableSSL; smtp.Credentials = smtpConfig.Credentials; smtp.Send(message); } catch (SmtpException ex) { Log(ex, "While sending mail. SMTP failure code: {4}.\n{0}", ex.StatusCode); return(false); } catch (Exception ex) { Log(ex, "While sending mail.\n{0}"); return(false); } finally { if (message != null) { message.Dispose(); } } return(true); }
public MailMessageFactoryTests() { _factory = new MailMessageFactory(); _smtpServerConfig = SmtpServerConfigFake.Generate(); var from = _faker.Internet.Email(); var to = new List <string>() { _faker.Internet.Email() }; _emailMessage = new EmailMessage(from, to, "subject", "body"); _request = new MailMessageCreateRequest() { EmailMessage = _emailMessage, SmtpServerConfig = _smtpServerConfig, IsReadSenderFromConfig = false, }; }
public ISmtpClient Create(SmtpServerConfig serverConfig) { var smtpHost = serverConfig.Host; var smtpPort = serverConfig.Port; var smtpClient = new SmtpClient(smtpHost, smtpPort) { DeliveryMethod = SmtpDeliveryMethod.Network, EnableSsl = false }; if (string.IsNullOrWhiteSpace(serverConfig.Login)) { smtpClient.UseDefaultCredentials = true; } else { smtpClient.Credentials = new NetworkCredential(serverConfig.Login, serverConfig.Password); } return(new SmtpClientProxy(smtpClient)); }
protected void Page_Load(object sender, EventArgs e) { if (Convert.ToBoolean(Session["IsLogged"])) { Response.Redirect(AppConfig.WebSite.MainPage); } Master.SetActiveNav(Account.ActiveNav.CreateAccount); SmtpServerConfig smtpServerConfig = new SmtpServerConfig() { Account = AppConfig.SmtpServer.Account, Password = AppConfig.SmtpServer.Password, Host = AppConfig.SmtpServer.Host, Port = AppConfig.SmtpServer.Port, DeliveryMethod = AppConfig.SmtpServer.DeliveryMethod, UseDefaultCredentials = AppConfig.SmtpServer.UseDefaultCredentials, EnableSsl = AppConfig.SmtpServer.EnableSsl }; lazyEmailService = new Lazy <EmailService>(() => new EmailService(smtpServerConfig)); }
public static SmtpServerConfig HasSenderAddress(this SmtpServerConfig config, string senderAddress) { config.SenderAddress = senderAddress; return(config); }
public static SmtpServerConfig HasSenderName(this SmtpServerConfig config, string senderName) { config.SenderName = senderName; return(config); }
public static SmtpServerConfig HasPassword(this SmtpServerConfig config, string password) { config.Password = password; return(config); }
public static SmtpServerConfig HasLogin(this SmtpServerConfig config, string login) { config.Login = login; return(config); }
public static SmtpServerConfig HasPort(this SmtpServerConfig config, int port) { config.Port = port; return(config); }
public static SmtpServerConfig HasHost(this SmtpServerConfig config, string host) { config.Host = host; return(config); }
public SmtpClientWithoutSslFactoryTests() { _factory = new SmtpClientWithoutSslFactory(); _smtpConfig = new SmtpServerConfig(); }
public SmtpServerConfigTests() { _config = new SmtpServerConfig(); }