Advertisement
Guest User

Untitled

a guest
Sep 28th, 2015
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. using System.Net;
  2. using System.Net.Mail;
  3.  
  4. /// <summary>
  5. ///
  6. //Brug af skolen SMTP
  7. //MailFac mf = new MailFac("vid233.vid.net.local", "hto@videndjurs.dk", "Henrik Obsen");
  8.  
  9. //Brug din egen gmail og Googles SMTP
  10. //MailFac mf = new MailFac("smtp.gmail.com", "email@gmail.com", "DitNavne", "password", 587);
  11.  
  12. //mf.Send("Emne","Body teksten.","hto@djes.dk");
  13. /// </summary>
  14. public class MailFac
  15. {
  16. private string _SMTP = "";
  17. private string _fromEmail = "";
  18. private string _fromName = "";
  19. private string _password = "";
  20. private int _port = 25;
  21.  
  22.  
  23. public MailFac(string SMTP, string fromEmail, string fromName)
  24. {
  25. _SMTP = SMTP;
  26. _fromEmail = fromEmail;
  27. _fromName = fromName;
  28. }
  29.  
  30. public MailFac(string SMTP, string fromEmail, string fromName, string password, int port)
  31. {
  32. _SMTP = SMTP;
  33. _fromEmail = fromEmail;
  34. _fromName = fromName;
  35. _password = password;
  36. _port = port;
  37. }
  38.  
  39. public void Send(string Subject, string Text, string Receiver)
  40. {
  41. MailMessage mail = new MailMessage();
  42.  
  43. mail.From = new MailAddress(_fromEmail, _fromName);
  44.  
  45. mail.To.Add(Receiver);
  46. mail.Subject = Subject;
  47. mail.Body = Text;
  48. mail.IsBodyHtml = true;
  49.  
  50. SmtpClient smtpCl = new SmtpClient(_SMTP, _port);
  51.  
  52. if (_password != "")
  53. {
  54. smtpCl.EnableSsl = true;
  55. smtpCl.UseDefaultCredentials = false;
  56. smtpCl.Credentials = new NetworkCredential(_fromEmail, _password);
  57. smtpCl.DeliveryMethod = SmtpDeliveryMethod.Network;
  58. }
  59.  
  60. smtpCl.Send(mail);
  61.  
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement