Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.IO;
- using System.Threading.Tasks;
- using System.Net.Mail;
- namespace kursovaya
- {
- class Program
- {
- class user_data
- {
- // использовать getter-setter для дальнейшего кода
- private protected string my_mail;
- private protected string some_mail;
- private protected string password;
- private protected string nickname;
- private protected string headline;
- public string UserMail
- {
- get { return my_mail;}
- set {
- if (value == "" | value == " ")
- {
- Console.WriteLine("Такое значение недопустимо при заполнении поля 'почта'. Значение сброшено до стандартного ");
- value = "obechekopm@gmail.com";
- }
- else
- {
- my_mail = value;
- }
- }
- }
- public void Print()
- {
- if (some_mail == "")
- {
- Console.WriteLine($"Письмо от адресанта {my_mail} отправлено адресату {my_mail}");
- }
- else
- {
- Console.WriteLine($"Письмо от адресанта {my_mail} отправлено адресату {some_mail}");
- }
- }
- }
- class Sendmail : user_data
- {
- public Sendmail(string email_address, string pass)
- {
- my_mail = email_address;
- nickname = "Anonymous";
- password = pass;
- headline = "Testing";
- MailAddress from = new MailAddress(my_mail, nickname);
- MailAddress to = new MailAddress(my_mail);
- MailMessage mess = new MailMessage(from, to);
- mess.Subject = headline;
- mess.Body = "<h2> Письмо-тест </h2>";
- mess.IsBodyHtml = true;
- SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
- smtp.Credentials = new NetworkCredential(my_mail, password);
- smtp.EnableSsl = true;
- smtp.Send(mess);
- Console.Read();
- }
- public Sendmail(
- string mail_1,
- string mail_2,
- string user_pass,
- string for_headline
- )
- {
- my_mail = mail_1;
- nickname = "Anonymous";
- some_mail = mail_2;
- password = user_pass;
- headline = for_headline;
- MailAddress from = new MailAddress(my_mail, nickname);
- MailAddress to = new MailAddress(some_mail);
- MailMessage mess = new MailMessage(from, to);
- mess.Subject = headline;
- mess.Body = "<h2> Письмо-тест </h2>";
- mess.IsBodyHtml = true;
- SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
- smtp.Credentials = new NetworkCredential(my_mail, password);
- smtp.EnableSsl = true;
- smtp.Send(mess);
- Console.Read();
- }
- public Sendmail(
- string username,
- string mail_1,
- string mail_2,
- string user_pass,
- string for_headline
- )
- {
- my_mail = mail_1;
- nickname = username;
- some_mail = mail_2;
- password = user_pass;
- headline = for_headline;
- MailAddress from = new MailAddress(my_mail, nickname);
- MailAddress to = new MailAddress(some_mail);
- MailMessage mess = new MailMessage(from, to);
- mess.Subject = headline;
- mess.Body = "<h2> Письмо-тест </h2>";
- mess.IsBodyHtml = true;
- SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
- smtp.Credentials = new NetworkCredential(my_mail, password);
- smtp.EnableSsl = true;
- smtp.Send(mess);
- Console.Read();
- }
- static void Main(string[] args)
- {
- string user_email = Console.ReadLine();
- string pas = Console.ReadLine();
- Sendmail some_mail = new Sendmail(user_email, pas);
- some_mail.Print();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement