Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void SendEmail(string fromAddress, string toLine, string subject, string messageBody)
- {
- const string host = "smtp.server.com";
- const int port = 1234;
- const string userName = "(user)";
- const string password = "password";
- using (var smtpClient = new SmtpClient(host, port))
- {
- smtpClient.Credentials = new NetworkCredential(userName, password);
- var mailMessage = new MailMessage(fromAddress, toLine, subject, messageBody);
- smtpClient.Send(mailMessage);
- }
- }
- private void SendEmailToAdmin(string message)
- {
- SmtpSection smtpSection = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;
- string host = smtpSection.Network.Host;
- if (string.IsNullOrEmpty(host))
- {
- host = "127.0.0.1";
- }
- using (SmtpClient smtpClient = new SmtpClient(host, smtpSection.Network.Port))
- {
- MailMessage mail = new MailMessage(smtpSection.From, Properties.Settings.Default.SupportEmailAddress);
- mail.Subject = Environment.MachineName + ": Error";
- mail.IsBodyHtml = false;
- mail.Body = message;
- smtpClient.Send(mail);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement