Advertisement
ZergRushA

cursov (final version, 06.03.2022)

Mar 6th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. using System.IO;
  4. using System.Threading.Tasks;
  5. using System.Net.Mail;
  6.  
  7.  
  8. namespace kursovaya
  9. {
  10. class Program
  11. {
  12. class user_data
  13. {
  14.  
  15. // использовать getter-setter для дальнейшего кода
  16. private protected string my_mail;
  17. private protected string some_mail;
  18. private protected string password;
  19. private protected string nickname;
  20. private protected string headline;
  21.  
  22. public string UserMail
  23. {
  24. get { return my_mail;}
  25.  
  26. set {
  27. if (value == "" | value == " ")
  28. {
  29. Console.WriteLine("Такое значение недопустимо при заполнении поля 'почта'. Значение сброшено до стандартного ");
  30. value = "obechekopm@gmail.com";
  31. }
  32. else
  33. {
  34. my_mail = value;
  35. }
  36.  
  37. }
  38. }
  39. public void Print()
  40. {
  41. if (some_mail == "")
  42. {
  43. Console.WriteLine($"Письмо от адресанта {my_mail} отправлено адресату {my_mail}");
  44. }
  45. else
  46. {
  47. Console.WriteLine($"Письмо от адресанта {my_mail} отправлено адресату {some_mail}");
  48. }
  49. }
  50.  
  51. }
  52. class Sendmail : user_data
  53. {
  54.  
  55.  
  56.  
  57.  
  58. public Sendmail(string email_address, string pass)
  59. {
  60. my_mail = email_address;
  61. nickname = "Anonymous";
  62. password = pass;
  63. headline = "Testing";
  64.  
  65. MailAddress from = new MailAddress(my_mail, nickname);
  66. MailAddress to = new MailAddress(my_mail);
  67. MailMessage mess = new MailMessage(from, to);
  68. mess.Subject = headline;
  69. mess.Body = "<h2> Письмо-тест </h2>";
  70. mess.IsBodyHtml = true;
  71. SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
  72. smtp.Credentials = new NetworkCredential(my_mail, password);
  73. smtp.EnableSsl = true;
  74. smtp.Send(mess);
  75. Console.Read();
  76.  
  77. }
  78.  
  79. public Sendmail(
  80. string mail_1,
  81. string mail_2,
  82. string user_pass,
  83. string for_headline
  84. )
  85. {
  86. my_mail = mail_1;
  87. nickname = "Anonymous";
  88. some_mail = mail_2;
  89. password = user_pass;
  90. headline = for_headline;
  91.  
  92. MailAddress from = new MailAddress(my_mail, nickname);
  93. MailAddress to = new MailAddress(some_mail);
  94. MailMessage mess = new MailMessage(from, to);
  95. mess.Subject = headline;
  96. mess.Body = "<h2> Письмо-тест </h2>";
  97. mess.IsBodyHtml = true;
  98. SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
  99. smtp.Credentials = new NetworkCredential(my_mail, password);
  100. smtp.EnableSsl = true;
  101. smtp.Send(mess);
  102. Console.Read();
  103.  
  104. }
  105.  
  106. public Sendmail(
  107. string username,
  108. string mail_1,
  109. string mail_2,
  110. string user_pass,
  111. string for_headline
  112. )
  113. {
  114. my_mail = mail_1;
  115. nickname = username;
  116. some_mail = mail_2;
  117. password = user_pass;
  118. headline = for_headline;
  119.  
  120. MailAddress from = new MailAddress(my_mail, nickname);
  121. MailAddress to = new MailAddress(some_mail);
  122. MailMessage mess = new MailMessage(from, to);
  123. mess.Subject = headline;
  124. mess.Body = "<h2> Письмо-тест </h2>";
  125. mess.IsBodyHtml = true;
  126. SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
  127. smtp.Credentials = new NetworkCredential(my_mail, password);
  128. smtp.EnableSsl = true;
  129. smtp.Send(mess);
  130. Console.Read();
  131.  
  132. }
  133.  
  134. static void Main(string[] args)
  135. {
  136. string user_email = Console.ReadLine();
  137. string pas = Console.ReadLine();
  138. Sendmail some_mail = new Sendmail(user_email, pas);
  139. some_mail.Print();
  140. }
  141.  
  142.  
  143. }
  144.  
  145. }
  146. }
  147.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement