public AutoreplyService(AutoreplyServiceConfiguration configuration = null) { configuration = configuration ?? AutoreplyServiceConfiguration.GetSection(); _storeIncomingMail = configuration.IsDebug; _mailFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), configuration.MailFolder); if (!Directory.Exists(_mailFolder)) { Directory.CreateDirectory(_mailFolder); } _smtpServer = new SMTP_Server { MaxBadCommands = configuration.SmtpConfiguration.MaxBadCommands, MaxTransactions = configuration.SmtpConfiguration.MaxTransactions, MaxMessageSize = configuration.SmtpConfiguration.MaxMessageSize, MaxRecipients = configuration.SmtpConfiguration.MaxRecipients, MaxConnectionsPerIP = configuration.SmtpConfiguration.MaxConnectionsPerIP, MaxConnections = configuration.SmtpConfiguration.MaxConnections, Bindings = new[] { new IPBindInfo("localhost", IPAddress.Any, configuration.SmtpConfiguration.Port, SslMode.None, null) }, }; _smtpServer.Error += OnSmtpError; _smtpServer.SessionCreated += OnSmtpSessionCreated; _cooldownInspector = new CooldownInspector(configuration.CooldownConfiguration); _apiService = new ApiService(configuration.Https); }
public AutoreplyService(AutoreplyServiceConfiguration configuration = null) { configuration = configuration ?? AutoreplyServiceConfiguration.GetSection(); _storeIncomingMail = configuration.IsDebug; _mailFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), configuration.MailFolder); if (!Directory.Exists(_mailFolder)) Directory.CreateDirectory(_mailFolder); _smtpServer = new SMTP_Server { MaxBadCommands = configuration.SmtpConfiguration.MaxBadCommands, MaxTransactions = configuration.SmtpConfiguration.MaxTransactions, MaxMessageSize = configuration.SmtpConfiguration.MaxMessageSize, MaxRecipients = configuration.SmtpConfiguration.MaxRecipients, MaxConnectionsPerIP = configuration.SmtpConfiguration.MaxConnectionsPerIP, MaxConnections = configuration.SmtpConfiguration.MaxConnections, Bindings = new[] {new IPBindInfo("localhost", IPAddress.Any, configuration.SmtpConfiguration.Port, SslMode.None, null)}, }; _smtpServer.Error += OnSmtpError; _smtpServer.SessionCreated += OnSmtpSessionCreated; _cooldownInspector = new CooldownInspector(configuration.CooldownConfiguration); _apiService = new ApiService(configuration.Https); }
protected override void Execute(CodeActivityContext context) { try { MailMessage message = new MailMessage(); SmtpClient smtp = new SmtpClient(); if (string.IsNullOrEmpty(FromEmailAddress.Get(context))) { message.From = new MailAddress(SMTP_Email.Get(context)); } else { message.From = new MailAddress(FromEmailAddress.Get(context)); } foreach (string emailid in ToEmailAddress.Get(context).Trim().Split(';')) { message.To.Add(new MailAddress(emailid)); } if (!string.IsNullOrEmpty(CCEmailAddress.Get(context))) { foreach (string emailid in CCEmailAddress.Get(context).Trim().Split(';')) { message.CC.Add(new MailAddress(emailid)); } } if (!string.IsNullOrEmpty(BccEmailAddress.Get(context))) { foreach (string emailid in BccEmailAddress.Get(context).Trim().Split(';')) { message.Bcc.Add(new MailAddress(emailid)); } } message.Subject = Subject.Get(context).Trim(); message.IsBodyHtml = IsBodyHtml.Get(context); //to make message body as html message.Body = Body.Get(context).Trim(); Console.WriteLine("----------------------"); if (MailAttachments.Get(context) != null) { Console.WriteLine("Number of Attachments: " + MailAttachments.Get(context).Count.ToString()); foreach (string file in MailAttachments.Get(context)) { message.Attachments.Add(new Attachment(file)); } } smtp.Port = Convert.ToInt32(SMTP_Port.Get(context)); smtp.Host = SMTP_Server.Get(context).Trim(); smtp.EnableSsl = EnableSsl.Get(context); smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential(SMTP_Email.Get(context), SMTP_password.Get(context)); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Send(message); IsSuccess.Set(context, true); Result.Set(context, string.Empty); } catch (Exception e) { Console.WriteLine("Error: " + e.Message + "--" + e.Source); IsSuccess.Set(context, false); Result.Set(context, "Error: " + e.Message); } }