Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Инициализация
- protected override void OnInit(HttpApplication application)
- {
- if (application == null)
- throw new ArgumentNullException("application");
- //
- // Get the configuration section of this module.
- // If it's not there then there is nothing to initialize or do.
- // In this case, the module is as good as mute.
- //
- IDictionary config = (IDictionary) GetConfig();
- if (config == null)
- return;
- //
- // Extract the settings.
- //
- string mailRecipient = GetSetting(config, "to");
- string mailSender = GetSetting(config, "from", mailRecipient);
- string mailCopyRecipient = GetSetting(config, "cc", string.Empty);
- string mailSubjectFormat = GetSetting(config, "subject", string.Empty);
- MailPriority mailPriority = (MailPriority) Enum.Parse(typeof(MailPriority), GetSetting(config, "priority", MailPriority.Normal.ToString()), true);
- bool reportAsynchronously = Convert.ToBoolean(GetSetting(config, "async", bool.TrueString));
- string smtpServer = GetSetting(config, "smtpServer", string.Empty);
- int smtpPort = Convert.ToUInt16(GetSetting(config, "smtpPort", "0"), CultureInfo.InvariantCulture);
- string authUserName = GetSetting(config, "userName", string.Empty);
- string authPassword = GetSetting(config, "password", string.Empty);
- bool sendYsod = Convert.ToBoolean(GetSetting(config, "noYsod", bool.FalseString));
- #if !NET_1_0 && !NET_1_1
- bool useSsl = Convert.ToBoolean(GetSetting(config, "useSsl", bool.FalseString));
- #endif
- //
- // Hook into the Error event of the application.
- //
- application.Error += new EventHandler(OnError);
- ErrorSignal.Get(application).Raised += new ErrorSignalEventHandler(OnErrorSignaled);
- //
- // Finally, commit the state of the module if we got this far.
- // Anything beyond this point should not cause an exception.
- //
- _mailRecipient = mailRecipient;
- _mailSender = mailSender;
- _mailCopyRecipient = mailCopyRecipient;
- _mailSubjectFormat = mailSubjectFormat;
- _mailPriority = mailPriority;
- _reportAsynchronously = reportAsynchronously;
- _smtpServer = smtpServer;
- _smtpPort = smtpPort;
- _authUserName = authUserName;
- _authPassword = authPassword;
- _noYsod = sendYsod;
- #if !NET_1_0 && !NET_1_1
- _useSsl = useSsl;
- #endif
- }
- //Посылка:
- SmtpClient client = new SmtpClient();
- string host = SmtpServer ?? string.Empty;
- if (host.Length > 0)
- {
- client.Host = host;
- client.DeliveryMethod = SmtpDeliveryMethod.Network;
- }
- int port = SmtpPort;
- if (port > 0)
- client.Port = port;
- string userName = AuthUserName ?? string.Empty;
- string password = AuthPassword ?? string.Empty;
- if (userName.Length > 0 && password.Length > 0)
- client.Credentials = new NetworkCredential(userName, password);
- client.EnableSsl = UseSsl;
- client.Send(mail);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement