Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net.Mail;
- using System.IO;
- using System.Net;
- using System.Security.Cryptography.X509Certificates;
- using System.Net.Security;
- namespace ms_web.Library
- {
- class MailGenerator
- {
- public string host;
- public int port;
- public string sender;
- public MailGenerator()
- {
- host = "10.1.0.9";
- port = 25;
- sender = "noreply.hrp@tsh.ssbshoes.com";
- ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
- { return true; };
- }
- public void send(string subject, string body, string[] receivers, string[] cc, string[] file)
- {
- MailMessage message = new MailMessage();
- foreach (string email in receivers)
- {
- message.To.Add(email);
- }
- foreach (string email in cc)
- {
- message.CC.Add(email);
- }
- message.From = new MailAddress(sender);
- message.Subject = subject;
- message.Body = body;
- message.IsBodyHtml = true;
- if (file.Length > 0)
- {
- foreach (var item in file)
- {
- Attachment attachment = new Attachment(item);
- message.Attachments.Add(attachment);
- }
- }
- executeMail(message);
- }
- private void executeMail(MailMessage message)
- {
- SmtpClient client = new SmtpClient(host, port);
- try
- {
- client.UseDefaultCredentials = false;
- client.Credentials = new NetworkCredential("tsh\'restu.adi", "p@55w0rd");
- //client.EnableSsl = true;
- client.Send(message);
- }
- catch (SmtpException ex)
- {
- string msg = ex.Message;
- if (ex.InnerException != null)
- {
- msg += "\n" + ex.InnerException.Message;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement