/// <summary>sends AUTHENTICATE command</summary> /// <remarks>valid in non-authenticated state</remarks> public ImapCommandResult Authenticate(ICredentialsByHost credentials, string username, ImapAuthenticationMechanism authenticationMechanism, bool reissueCapability) { var ret = RejectNonConnectedOrGetAuthenticatedResult(); if (ret != null) return ret; if (credentials == null) throw new ArgumentNullException("credentials"); if (authenticationMechanism == null) throw new ArgumentNullException("authenticationMechanism"); var credential = credentials.LookupCredential(connection, username, authenticationMechanism); if (credential == null) return new ImapCommandResult(ImapCommandResultCode.RequestError, string.Format("credential not found for {0};AUTH={1}@{2}:{3}", username, authenticationMechanism, connection.Host, connection.Port)); using (var t = new AuthenticateTransaction(connection, credential, serverCapabilities.Has(ImapCapability.SaslIR))) { t.RequestArguments["authentication mechanism name"] = authenticationMechanism; return AuthenticateInternal(t, credential.UserName, authenticationMechanism, reissueCapability); } }
/// <summary> /// Adds a sink that sends log events via email. /// </summary> /// <param name="loggerConfiguration">The logger configuration.</param> /// <param name="fromEmail">The email address emails will be sent from</param> /// <param name="toEmail">The email address emails will be sent to</param> /// <param name="mailServer">The SMTP email server to use</param> /// <param name="networkCredential">The network credentials to use to authenticate with mailServer</param> /// <param name="outputTemplate">A message template describing the format used to write to the sink. /// the default is "{Timestamp} [{Level}] {Message:l}{NewLine:l}{Exception:l}".</param> /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param> /// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param> /// <param name="period">The time to wait between checking for event batches.</param> /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> /// <returns>Logger configuration, allowing configuration to continue.</returns> /// <exception cref="ArgumentNullException">A required parameter is null.</exception> public static LoggerConfiguration Email( this LoggerSinkConfiguration loggerConfiguration, string fromEmail, string toEmail, string mailServer, ICredentialsByHost networkCredential, string outputTemplate = DefaultOutputTemplate, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, int batchPostingLimit = EmailSink.DefaultBatchPostingLimit, TimeSpan? period = null, IFormatProvider formatProvider = null) { if (loggerConfiguration == null) throw new ArgumentNullException("loggerConfiguration"); if (fromEmail == null) throw new ArgumentNullException("fromEmail"); if (toEmail == null) throw new ArgumentNullException("toEmail"); if (mailServer == null) throw new ArgumentNullException("mailServer"); var defaultedPeriod = period ?? EmailSink.DefaultPeriod; var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); return loggerConfiguration.Sink( new EmailSink(fromEmail, toEmail, mailServer, networkCredential, batchPostingLimit, defaultedPeriod, formatter), restrictedToMinimumLevel); }
/// <summary> /// Adds a sink that sends log events via email. /// </summary> /// <param name="loggerConfiguration">The logger configuration.</param> /// <param name="fromEmail">The email address emails will be sent from</param> /// <param name="toEmail">The email address emails will be sent to</param> /// <param name="mailServer">The SMTP email server to use</param> /// <param name="networkCredential">The network credentials to use to authenticate with mailServer</param> /// <param name="outputTemplate">A message template describing the format used to write to the sink. /// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param> /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param> /// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param> /// <param name="period">The time to wait between checking for event batches.</param> /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> /// <returns>Logger configuration, allowing configuration to continue.</returns> /// <exception cref="ArgumentNullException">A required parameter is null.</exception> public static LoggerConfiguration Email( this LoggerSinkConfiguration loggerConfiguration, string fromEmail, string toEmail, string mailServer, ICredentialsByHost networkCredential, string outputTemplate = DefaultOutputTemplate, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, int batchPostingLimit = EmailSink.DefaultBatchPostingLimit, TimeSpan? period = null, IFormatProvider formatProvider = null) { if (loggerConfiguration == null) throw new ArgumentNullException("loggerConfiguration"); if (fromEmail == null) throw new ArgumentNullException("fromEmail"); if (toEmail == null) throw new ArgumentNullException("toEmail"); if (mailServer == null) throw new ArgumentNullException("mailServer"); var connectionInfo = new EmailConnectionInfo { FromEmail = fromEmail, ToEmail = toEmail, MailServer = mailServer, NetworkCredentials = networkCredential }; return Email(loggerConfiguration, connectionInfo, outputTemplate, restrictedToMinimumLevel, batchPostingLimit, period, formatProvider); }
public EmailSender(string smtpHost, string username, string password, int port) { _smtpServer = new SmtpClient(smtpHost); _smtpServer.Port = port; _credentials = new System.Net.NetworkCredential(username, password); _smtpServer.EnableSsl = true; _smtpServer.UseDefaultCredentials = false; }
/// <summary> /// Creates a new smart file stream logger class instance /// </summary> public SmartFileLogger(string smtpHost, int smtpPort, string fromAddress, string toAddress, ICredentialsByHost smtpCredentials, IClock timer, LogType level, bool writeToConsole, string logFolderPath) : base(timer, level, writeToConsole, logFolderPath) { this.smtpHost = smtpHost; this.smtpPort = smtpPort; this.fromAddress = fromAddress; this.toAddress = toAddress; this.smtpCredentials = smtpCredentials; }
internal SmtpConnection(SmtpTransport parent, SmtpClient client, ICredentialsByHost credentials, ISmtpAuthenticationModule[] authenticationModules) { this.client = client; this.credentials = credentials; this.authenticationModules = authenticationModules; this.parent = parent; onCloseHandler = new EventHandler(OnClose); }
private void InitUseCoreSettings() { var s = CoreContext.Configuration.SmtpSettings; host = s.Host; port = s.Port.GetValueOrDefault(25); ssl = s.EnableSSL; credentials = new NetworkCredential(s.CredentialsUserName, s.CredentialsUserPassword, s.CredentialsDomain); }
internal SmtpConnection(SmtpTransport parent, SmtpClient client, ICredentialsByHost credentials, ISmtpAuthenticationModule[] authenticationModules) { this.client = client; this.credentials = credentials; this.authenticationModules = authenticationModules; this.parent = parent; this.onCloseHandler = new EventHandler(this.OnClose); }
public void Credentials_Unset_Null() { SmtpClient client = new SmtpClient(); ICredentialsByHost transportCredentials = GetTransportCredentials(client); Assert.Null(client.Credentials); Assert.Null(transportCredentials); }
public EmailSender(ILoggerFactory loggerFactory, IConfiguration configuration) { smtpServer = configuration.GetValue <string>("SMTP_HOST"); smtpPort = configuration.GetValue <int?>("SMTP_PORT") ?? 25; defaultSender = configuration.GetValue <string>("SMTP_DEFAULT_SENDER"); credentials = string.IsNullOrEmpty(configuration["SMTP_USER"]) ? null : new NetworkCredential(configuration.GetValue <string>("SMTP_USER"), configuration.GetValue <string>("SMTP_PASSWORD")); enableSSL = configuration.GetValue <bool?>("SMTP_ENABLE_SSL") ?? false; logger = loggerFactory.CreateLogger(typeof(EmailSender)); }
internal SmtpConnection(SmtpTransport parent, SmtpClient client, ICredentialsByHost credentials, ISmtpAuthenticationModule[] authenticationModules) { _client = client; _credentials = credentials; _authenticationModules = authenticationModules; _parent = parent; _tcpClient = new TcpClient(); _onCloseHandler = new EventHandler(OnClose); }
private void InitUseCoreSettings() { var s = CoreContext.Configuration.SmtpSettings; host = s.Host; port = s.Port; ssl = s.EnableSSL; credentials = new NetworkCredential(s.CredentialsUserName, s.CredentialsUserPassword, s.CredentialsDomain); }
/// <summary> /// Creates a new smart file stream logger class instance /// </summary> public SmartFileLogger(string smtpHost, int smtpPort, string fromAddress, string toAddress, bool smtpEnableSsl, ICredentialsByHost smtpCredentials, bool writeToConsole, string logFolderPath, IClock timer, LogType level = LogType.All) : base(writeToConsole, logFolderPath, timer, level) { this.smtpHost = smtpHost; this.smtpPort = smtpPort; this.fromAddress = fromAddress; this.toAddress = toAddress; this.smtpEnableSsl = smtpEnableSsl; this.smtpCredentials = smtpCredentials; }
public BclSmtpClient(string mailServer, ICredentialsByHost credentials) { _smtpClient = new SmtpClient(mailServer) { EnableSsl = false, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = credentials }; }
public static void SendEmail(string from, string to, string subject, string messageText) { MeljabCredentials meljabCredentials = new MeljabCredentials(); ICredentialsByHost creds = meljabCredentials.GetCredential(); SchwabenCode.EasySmtp.GMailSmtp gmailSmtp = new GMailSmtp(creds); MailMessage mailMessage = new MailMessage(from, to, subject, messageText); gmailSmtp.Send(mailMessage); }
public static void SendEmail(string messageText) { MeljabCredentials meljabCredentials = new MeljabCredentials(); ICredentialsByHost creds = meljabCredentials.GetCredential(); SchwabenCode.EasySmtp.GMailSmtp gmailSmtp = new GMailSmtp(creds); MailMessage mailMessage = new MailMessage("*****@*****.**", "*****@*****.**", "From MeljabUtility: Your External IP Address", messageText); gmailSmtp.Send(mailMessage); }
private void sendMail(Notification notification) { var users = db.Users.ToList(); NotificationViewModel vnotification = new NotificationViewModel { Id = notification.Id, SenderId = notification.SenderId, SenderName = users.Where(m => m.Id == notification.SenderId).SingleOrDefault().UserName, RecipientId = notification.RecipientId, RecipientName = users.Where(m => m.Id == notification.RecipientId).SingleOrDefault().UserName, AbsenceCategoryId = notification.AbsenceCategoryId, AbsenceCategoryName = db.AbsenceCategories.Where(m => m.Id == notification.AbsenceCategoryId).SingleOrDefault().CategoryName, Description = notification.Description, Date = notification.Date, DateFrom = notification.DateFrom, DateTo = notification.DateTo }; MailViewModel mail = new MailViewModel(); mail.FromEmail = User.Identity.Name; mail.Message = "<div>" + "<h3>Notification</h3>" + "<hr />" + "<dl class=\"dl - horizontal\">" + "<dt><strong>Employee</strong></dt>" + "<dd>" + mail.FromEmail + "</dd>" + "<dt><strong>Absence category</strong></dt>" + "<dd>" + vnotification.AbsenceCategoryName + "</dd>" + "<dt><strong>Description</strong></dt>" + "<dd>" + vnotification.Description + "</dd>" + "<dt><strong>Date</strong></dt>" + "<dd>" + vnotification.Date + "</dd>" + "<dt><strong>Date from</strong></dt>" + "<dd>" + vnotification.DateFrom + "</dd>" + "<dt><strong>Date to</strong></dt>" + "<dd>" + vnotification.DateTo + "</dd>" + "</dl>" + "</div>"; var body = "<p>Email From: {0} </p><p>Message:</p><p>{1}</p>"; var message = new MailMessage(); message.To.Add(new MailAddress(db.Users.Where(m => m.Id == notification.RecipientId).SingleOrDefault().Email)); message.Subject = "Notification"; message.Body = string.Format(body, mail.FromEmail, mail.Message); message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { ICredentialsByHost credentials = smtp.Credentials; smtp.UseDefaultCredentials = true; smtp.Credentials = credentials; smtp.Send(message); } }
public void UseDefaultCredentials_False_Null() { SmtpClient client = new SmtpClient(); client.UseDefaultCredentials = false; ICredentialsByHost transportCredentials = GetTransportCredentials(client); Assert.Null(client.Credentials); Assert.Null(transportCredentials); }
/// <summary> /// Init smtp server by sharepoint /// </summary> /// <param name="host"></param> /// <param name="c"></param> protected void InitSmtpClient(string host, int port, ICredentialsByHost c) { client.Host = host; if (port > 0) { client.Port = port; } client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = EnableSSL; client.UseDefaultCredentials = false; client.Credentials = c; }
public SendMail(string smtpServer, int smtpPort, ICredentialsByHost credentials) { Client = new SmtpClient(); Client.Host = smtpServer; Client.Port = smtpPort; // Default for GMail is 587. Client.DeliveryMethod = SmtpDeliveryMethod.Network; Client.UseDefaultCredentials = false; Client.EnableSsl = true; Client.Timeout = 10000; Client.Credentials = credentials; From = ((System.Net.NetworkCredential)credentials).UserName; }
public virtual void Init(IDictionary<string, string> properties) { host = properties["host"]; port = properties.ContainsKey("port") ? int.Parse(properties["port"]) : 25; ssl = properties.ContainsKey("enableSsl") ? bool.Parse(properties["enableSsl"]) : false; if (properties.ContainsKey("userName")) { credentials = new NetworkCredential( properties["userName"], properties["password"], properties.ContainsKey("domain") ? properties["domain"] : string.Empty); } }
public void DefaultCredentials_True_DefaultCredentials() { NetworkCredential expectedCredentials = CredentialCache.DefaultNetworkCredentials; SmtpClient client = new SmtpClient(); client.UseDefaultCredentials = true; ICredentialsByHost transportCredentials = GetTransportCredentials(client); Assert.Equal(expectedCredentials, client.Credentials); Assert.Equal(expectedCredentials, transportCredentials); }
public virtual void Init(IDictionary <string, string> properties) { host = properties["host"]; port = properties.ContainsKey("port") ? int.Parse(properties["port"]) : 25; ssl = properties.ContainsKey("enableSsl") ? bool.Parse(properties["enableSsl"]) : false; if (properties.ContainsKey("userName")) { credentials = new NetworkCredential( properties["userName"], properties["password"], properties.ContainsKey("domain") ? properties["domain"] : string.Empty); } }
/// <summary> /// Construct a sink emailing with the specified details. /// </summary> /// <param name="fromEmail">The email address emails will be sent from</param> /// <param name="toEmail">The email address emails will be sent to</param> /// <param name="mailServer">The SMTP email server to use</param> /// <param name="networkCredential">The network credentials to use to authenticate with mailServer</param> /// <param name="batchSizeLimit">The maximum number of events to post in a single batch.</param> /// <param name="period">The time to wait between checking for event batches.</param> /// <param name="textFormatter">Supplies culture-specific formatting information, or null.</param> public EmailSink(string fromEmail, string toEmail, string mailServer, ICredentialsByHost networkCredential, int batchSizeLimit, TimeSpan period, ITextFormatter textFormatter) : base(batchSizeLimit, period) { if (fromEmail == null) throw new ArgumentNullException("fromEmail"); if (toEmail == null) throw new ArgumentNullException("toEmail"); if (mailServer == null) throw new ArgumentNullException("mailServer"); _fromEmail = fromEmail; _toEmail = toEmail; _textFormatter = textFormatter; _smtpClient = new SmtpClient(mailServer) {Credentials = networkCredential}; _smtpClient.SendCompleted += SendCompletedCallback; }
public void Credentials_UseDefaultCredentialsSetTrueBeforeCredentials_DefaultNetworkCredentials() { NetworkCredential expectedCredentials = CredentialCache.DefaultNetworkCredentials; SmtpClient client = new SmtpClient(); client.UseDefaultCredentials = true; client.Credentials = new NetworkCredential(UserName, Password); ICredentialsByHost transportCredentials = GetTransportCredentials(client); Assert.Equal(expectedCredentials, client.Credentials); Assert.Equal(expectedCredentials, transportCredentials); }
private static void SendCallback(object state) { object[] states = (object[])state; MailMessage message = states[0] as MailMessage; ICredentialsByHost credentials = states[1] as ICredentialsByHost; if (!Send(message, credentials)) { // Console.WriteLine( "Sent e-mail '{0}' to '{1}'.", message.Subject, message.To ); //else Console.WriteLine("Failure sending e-mail '{0}' to '{1}'.", message.Subject, message.To); } }
public void Credentials_UseDefaultCredentialsSetFalseAfterCredentials_Credentials() { NetworkCredential expectedCredentials = new NetworkCredential(UserName, Password); SmtpClient client = new SmtpClient(); client.Credentials = expectedCredentials; client.UseDefaultCredentials = false; ICredentialsByHost transportCredentials = GetTransportCredentials(client); Assert.NotNull(client.Credentials); Assert.Equal(expectedCredentials, client.Credentials); Assert.Equal(expectedCredentials, transportCredentials); }
public static void SmtpSend(string host, int port, MailMessage mail, ICredentialsByHost cred) { var smtp = new SmtpClient(); if (cred != null) { smtp.UseDefaultCredentials = false; smtp.Credentials = cred; } smtp.EnableSsl = true; smtp.Host = host; smtp.Port = port; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Send(mail); }
public LogEmail(LogEmailSettings setting) { ApplySettings(setting); EnableSsl = setting.EnableSsl; Host = setting.Host; Port = setting.Port; UseDefaultCredentials = setting.UseDefaultCredentials; if (UseDefaultCredentials) { Credentials = new NetworkCredential(userName: setting.UserName, password: setting.Password); } MailAddresses = setting.MailAddresses; if (setting.FromAddress != null) { FromAddress = new MailAddress(setting.FromAddress); } }
public SmtpHandler(string host, int port, SmtpDeliveryMethod method, ICredentialsByHost credentials, bool enableSsl) { this.Host = host; this.Port = port; this.DeliveryMethod = method; this.Credentials = credentials; this.EnableSsl = enableSsl; this._smtpClient = new SmtpClient { Host = this.Host, Port = this.Port, DeliveryMethod = this.DeliveryMethod, Credentials = this.Credentials, EnableSsl = this.EnableSsl, }; }
/// <summary> /// Creates a new instance of Email. /// </summary> /// <param name="mailhost">Predefined mail server. Value should not be a CustomMail</param> /// <param name="uid">Mail account user id</param> /// <param name="pwd">Mail account password</param> public Email(MailHostEnum mailhost, string uid, string pwd) { _mailhost = mailhost; _uid = uid; _pwd = pwd; switch (mailhost) { case MailHostEnum.FMS: _host = fmsmail; break; case MailHostEnum.Gmail: _host = gmail; _port = 465; break; case MailHostEnum.YahooMail: _host = yahoomail; _port = 587; break; case MailHostEnum.CustomMail: case MailHostEnum.None: default: throw new Exception("Mail should not be other than FMS, Gmail or Yahoo mail host."); } if (_mailhost == MailHostEnum.FMS) { _smtp = new SmtpClient(_host); } else { if (_port > 0) { _smtp = new SmtpClient(_host, _port); } else { _smtp = new SmtpClient(_host); } _smtp.EnableSsl = true; _smtp.UseDefaultCredentials = false; } if (!String.IsNullOrEmpty(uid.RLTrim()) && !String.IsNullOrEmpty(pwd.RLTrim())) { _credentials = new NetworkCredential(uid, pwd); } }
/// <summary> /// Envia un mensaje de correo electronico utilizando credenciales enviadas por parámetros. /// </summary> /// <param name="pFrom">Remitente.</param> /// <param name="pTo">Destinatario.</param> /// <param name="pCC">Destinatario con copia carbonica.</param> /// <param name="pBCC">Destinatario con copia carbonica oculta.</param> /// <param name="pSubject">Asunto.</param> /// <param name="pBody">Cuerpo del mail.</param> /// <param name="pBodyHtml">Indica si el contenido es html o no.</param> /// <param name="pAttachments">Ruta de archivos adjuntos.</param> /// <param name="pCredentials">Credenciales para autenticar el usuario que envía el mail.</param> /// <Date>2006-04-18T00:00:00</Date> /// <Author>moviedo</Author> public static void SendMail(string pFrom, string pTo, string pCC, string pBCC, string pSubject, string pBody, bool pBodyHtml, string[] pAttachments, ICredentialsByHost pCredentials) { using (MailMessage wMsg = new MailMessage(pFrom, pTo, pSubject, pBody)) { SmtpClient wClient = null; wMsg.IsBodyHtml = pBodyHtml; if (pCC != null && !pCC.Equals(string.Empty)) { wMsg.CC.Add(pCC); } if (pBCC != null && !pBCC.Equals(string.Empty)) { wMsg.Bcc.Add(pBCC); } if (pAttachments != null) { foreach (string wFileName in pAttachments) { wMsg.Attachments.Add(new Attachment(wFileName)); } } try { wClient = new SmtpClient(); if (pCredentials != null) { wClient.Credentials = pCredentials; } wClient.Send(wMsg); } finally { wClient = null; } } }
public static bool Send(MailMessage message, ICredentialsByHost credentials) { try { lock ( _Client ) { //If this is not specified, we would like to keep it that way. _Client.Credentials = credentials; _Client.Send(message); } } catch (Exception e) { Console.WriteLine("Email Send: Failure: {0}", e); return(false); } return(true); }
public virtual void Init(IDictionary <string, string> properties) { if (properties.ContainsKey("useCoreSettings") && bool.Parse(properties["useCoreSettings"])) { useCoreSettings = true; } else { host = properties["host"]; port = properties.ContainsKey("port") ? int.Parse(properties["port"]) : 25; ssl = properties.ContainsKey("enableSsl") && bool.Parse(properties["enableSsl"]); if (properties.ContainsKey("userName")) { credentials = new NetworkCredential( properties["userName"], properties["password"]); } } }
/// <summary> /// Creates a new instance of Email. /// </summary> /// <param name="host">Mail server hostname</param> /// <param name="port">Mail server port number</param> /// <param name="uid">Mail account user id</param> /// <param name="pwd">Mail account password</param> public Email(string host, int port, string uid, string pwd) { _uid = uid; _pwd = pwd; _host = host; _port = port; if (_port > 0) { _smtp = new SmtpClient(_host, _port); } else { _smtp = new SmtpClient(_host); } if (!String.IsNullOrEmpty(uid.RLTrim()) && !String.IsNullOrEmpty(pwd.RLTrim())) { _credentials = new NetworkCredential(uid, pwd); } }
public NotificationServiceImpl(IEntityRepository repository, ISecurityService securityService, IFileService fileService, IDatabaseService dbService) { _repository = repository; _securityService = securityService; _fileService = fileService; _dbService = dbService; var config = ConfigurationManager.GetSection("emailNotification") as EmailNotificationSection; _host = config.SmtpServer; _port = config.SmtpPort; _from = config.From; _testingMode = config.TestingMode; _useDefaultCreds = config.UseDefaultCredentials; if (!string.IsNullOrEmpty(config.User) || !string.IsNullOrEmpty(config.Password)) { _credentials = new NetworkCredential(config.User, config.Password); } }
/// <summary> /// Adds a sink that sends log events via email. /// </summary> /// <param name="loggerConfiguration">The logger configuration.</param> /// <param name="fromEmail">The email address emails will be sent from</param> /// <param name="toEmail">The email address emails will be sent to</param> /// <param name="mailServer">The SMTP email server to use</param> /// <param name="networkCredential">The network credentials to use to authenticate with mailServer</param> /// <param name="outputTemplate">A message template describing the format used to write to the sink. /// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param> /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param> /// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param> /// <param name="period">The time to wait between checking for event batches.</param> /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> /// <returns>Logger configuration, allowing configuration to continue.</returns> /// <exception cref="ArgumentNullException">A required parameter is null.</exception> public static LoggerConfiguration Email( this LoggerSinkConfiguration loggerConfiguration, string fromEmail, string toEmail, string mailServer, ICredentialsByHost networkCredential, string outputTemplate = DefaultOutputTemplate, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, int batchPostingLimit = EmailSink.DefaultBatchPostingLimit, TimeSpan?period = null, IFormatProvider formatProvider = null) { if (loggerConfiguration == null) { throw new ArgumentNullException("loggerConfiguration"); } if (fromEmail == null) { throw new ArgumentNullException("fromEmail"); } if (toEmail == null) { throw new ArgumentNullException("toEmail"); } if (mailServer == null) { throw new ArgumentNullException("mailServer"); } var connectionInfo = new EmailConnectionInfo { FromEmail = fromEmail, ToEmail = toEmail, MailServer = mailServer, NetworkCredentials = networkCredential }; return(Email(loggerConfiguration, connectionInfo, outputTemplate, restrictedToMinimumLevel, batchPostingLimit, period, formatProvider)); }
/// <summary>sends APOP command</summary> /// <remarks>valid in authorization state</remarks> public PopCommandResult Apop(ICredentialsByHost credentials, string username) { if (credentials == null) throw new ArgumentNullException("credentials"); var ret = RejectNonConnectedOrGetAuthenticatedResult(); if (ret != null) return ret; if (!ApopAvailable) throw new PopIncapableException("server does not support APOP"); NetworkCredential credential; ret = LookupAppropriateCredential(credentials, username, PopAuthenticationMechanism.Apop, out credential); if (ret != null) return ret; else if (string.IsNullOrEmpty(credential.UserName)) return new PopCommandResult(PopCommandResultCode.RequestError, "username of credential is empty"); else if (string.IsNullOrEmpty(credential.Password)) return new PopCommandResult(PopCommandResultCode.RequestError, "password of credential is empty"); using (var t = new ApopTransaction(connection)) { t.RequestArguments["name"] = credential.UserName; t.RequestArguments["digest"] = ApopDigest.Calculate(timestamp, credential.Password); if (ProcessTransaction(t).Succeeded) { UpdateAuthority(credential.UserName, PopAuthenticationMechanism.Apop); TransitStateTo(PopSessionState.Transaction); } return t.Result; } }
/// <summary> /// Adds a sink that sends log events via email. /// </summary> /// <param name="loggerConfiguration">The logger configuration.</param> /// <param name="fromEmail">The email address emails will be sent from</param> /// <param name="toEmails">The email addresses emails will be sent to</param> /// <param name="mailServer">The SMTP email server to use</param> /// <param name="networkCredential">The network credentials to use to authenticate with mailServer</param> /// <param name="outputTemplate">A message template describing the format used to write to the sink. /// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param> /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param> /// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param> /// <param name="period">The time to wait between checking for event batches.</param> /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> /// <param name="mailSubject">The subject, can be a plain string or a template such as {Timestamp} [{Level}] occurred.</param> /// <returns>Logger configuration, allowing configuration to continue.</returns> /// <exception cref="ArgumentNullException">A required parameter is null.</exception> public static LoggerConfiguration Email( this LoggerSinkConfiguration loggerConfiguration, string fromEmail, IEnumerable <string> toEmails, string mailServer, ICredentialsByHost networkCredential = null, string outputTemplate = SerilogExtensions.DefaultOutputTemplate, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, int batchPostingLimit = DefaultBatchPostingLimit, TimeSpan?period = null, IFormatProvider formatProvider = null, string mailSubject = EmailConfig.DefaultSubject) { if (loggerConfiguration == null) { throw new ArgumentNullException("loggerConfiguration"); } if (fromEmail == null) { throw new ArgumentNullException("fromEmail"); } if (toEmails == null) { throw new ArgumentNullException("toEmails"); } var emailConfig = new EmailConfig { FromEmail = fromEmail, ToEmail = string.Join(";", toEmails), MailServer = mailServer, NetworkCredentials = networkCredential, EmailSubject = mailSubject }; return(Email(loggerConfiguration, emailConfig, outputTemplate, restrictedToMinimumLevel, batchPostingLimit, period, formatProvider, mailSubject)); }
/// <summary> /// Adds a sink that sends log events via email. /// </summary> /// <param name="loggerConfiguration">The logger configuration.</param> /// <param name="fromEmail">The email address emails will be sent from</param> /// <param name="toEmail">The email address emails will be sent to</param> /// <param name="mailServer">The SMTP email server to use</param> /// <param name="networkCredential">The network credentials to use to authenticate with mailServer</param> /// <param name="outputTemplate">A message template describing the format used to write to the sink. /// the default is "{Timestamp} [{Level}] {Message:l}{NewLine:l}{Exception:l}".</param> /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param> /// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param> /// <param name="period">The time to wait between checking for event batches.</param> /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param> /// <returns>Logger configuration, allowing configuration to continue.</returns> /// <exception cref="ArgumentNullException">A required parameter is null.</exception> public static LoggerConfiguration Email( this LoggerSinkConfiguration loggerConfiguration, string fromEmail, string toEmail, string mailServer, ICredentialsByHost networkCredential, string outputTemplate = DefaultOutputTemplate, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, int batchPostingLimit = EmailSink.DefaultBatchPostingLimit, TimeSpan?period = null, IFormatProvider formatProvider = null) { if (loggerConfiguration == null) { throw new ArgumentNullException("loggerConfiguration"); } if (fromEmail == null) { throw new ArgumentNullException("fromEmail"); } if (toEmail == null) { throw new ArgumentNullException("toEmail"); } if (mailServer == null) { throw new ArgumentNullException("mailServer"); } var defaultedPeriod = period ?? EmailSink.DefaultPeriod; var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); return(loggerConfiguration.Sink( new EmailSink(fromEmail, toEmail, mailServer, networkCredential, batchPostingLimit, defaultedPeriod, formatter), restrictedToMinimumLevel)); }
public void Connect(ICredentialsByHost credentials, UpgradeConnectionStreamCallback createSslStreamCallback) { ThrowIfAlreadyConnectedOrAsyncConnectRunning(); SetSession(ConnectCore(new ConnectParams(profile, credentials, createSslStreamCallback))); }
internal void SetCredentials(ICredentialsByHost credentials) { this.credentials = credentials; }
public IAsyncResult BeginConnect(ICredentialsByHost credentials, UpgradeConnectionStreamCallback createSslStreamCallback) { return BeginConnect(credentials, createSslStreamCallback, null, null); }
/// <summary>sends AUTHENTICATE command</summary> /// <remarks>valid in non-authenticated state</remarks> public ImapCommandResult Authenticate(ICredentialsByHost credentials, string username, ImapAuthenticationMechanism authenticationMechanism) { return Authenticate(credentials, username, authenticationMechanism, false); }
/// <summary>sends AUTHENTICATE command</summary> /// <remarks>valid in non-authenticated state</remarks> public ImapCommandResult Authenticate(ICredentialsByHost credentials, ImapAuthenticationMechanism authenticationMechanism, bool reissueCapability) { return Authenticate(credentials, null, authenticationMechanism, reissueCapability); }
/// <summary>sends LOGIN command</summary> /// <remarks>valid in non-authenticated state</remarks> public ImapCommandResult Login(ICredentialsByHost credentials, string username, bool reissueCapability) { var ret = RejectNonConnectedOrGetAuthenticatedResult(); if (ret != null) return ret; // RFC 2595 Using TLS with IMAP, POP3 and ACAP // http://tools.ietf.org/html/rfc2595 // 3.2. IMAP LOGINDISABLED capability // An IMAP client which complies with this specification MUST NOT issue // the LOGIN command if this capability is present. if (serverCapabilities.Has(Imap4.ImapCapability.LoginDisabled)) throw new ImapIncapableException("LOGIN is disabled"); if (credentials == null) throw new ArgumentNullException("credentials"); var credential = credentials.LookupCredential(connection, username, null); if (credential == null) return new ImapCommandResult(ImapCommandResultCode.RequestError, string.Format("credential not found for {0}@{1}:{2}", username, connection.Host, connection.Port)); using (var t = new LoginTransaction(connection, credential)) { return AuthenticateInternal(t, credential.UserName, null, reissueCapability); } }
public static void AsyncSend( MailMessage message, ICredentialsByHost credentials ) { ThreadPool.QueueUserWorkItem( new WaitCallback( SendCallback ), new object[]{ message, credentials } ); }
/// <summary>sends LOGIN command</summary> /// <remarks>valid in non-authenticated state</remarks> public ImapCommandResult Login(ICredentialsByHost credentials, bool reissueCapability) { return Login(credentials, null, reissueCapability); }
/// <summary>sends LOGIN command</summary> /// <remarks>valid in non-authenticated state</remarks> public ImapCommandResult Login(ICredentialsByHost credentials) { return Login(credentials, false); }
public IAsyncResult BeginConnect(ICredentialsByHost credentials) { return BeginConnect(credentials, null, null, null); }
public SmtpEmailProvider(string host, int port, ICredentialsByHost credentials) { _client = () => new SmtpClient { Host = host, Port = port, Credentials = credentials }; }
public IAsyncResult BeginConnect(ICredentialsByHost credentials, UpgradeConnectionStreamCallback createSslStreamCallback, AsyncCallback asyncCallback, object asyncState) { return BeginConnect(new ConnectParams(profile, credentials, createSslStreamCallback), asyncCallback, asyncState); }
public static bool Send( MailMessage message, ICredentialsByHost credentials ) { try { lock ( _Client ) { //If this is not specified, we would like to keep it that way. _Client.Credentials = credentials; _Client.Send( message ); } } catch ( Exception e ) { Console.WriteLine( "Email Send: Failure: {0}", e ); return false; } return true; }
public void Connect(ICredentialsByHost credentials) { ThrowIfAlreadyConnectedOrAsyncConnectRunning(); SetSession(ConnectCore(new ConnectParams(profile, credentials, null))); }
/// <summary>sends LOGIN command</summary> /// <remarks>valid in non-authenticated state</remarks> public ImapCommandResult Login(ICredentialsByHost credentials, string username) { return Login(credentials, username, false); }
public SmtpEmailService(ICredentialsByHost credential, SmtpServerParams parameters) { _credential = credential; _parameters = parameters; }
public ConnectParams(ImapClientProfile profile, ICredentialsByHost credentials, UpgradeConnectionStreamCallback createSslStreamCallback) { Profile = profile.Clone(); Profile.SetCredentials(credentials); CreateSslStreamCallback = createSslStreamCallback; }
public IAsyncResult BeginConnect(ICredentialsByHost credentials, AsyncCallback asyncCallback, object asyncState) { return BeginConnect(credentials, null, asyncCallback, asyncState); }