private void CreatButton_Click(object sender, RoutedEventArgs e) { MessageContet msg = new MessageContet(); MessageBodyValue.Text = msg.Body; MessageSubjectValue.Text = msg.Subject; UserEmailValue.Text = LoginValue.Text; MessageEmailsValue.Text = UserEmailValue.Text; }
private void SendButton_Click(object sender, RoutedEventArgs e) { PersonMail author = new PersonMail { Login = LoginValue.Text, Password = PasswordValue.SecurePassword, Name = UserNameValue.Text, Email = UserEmailValue.Text }; MessageContet msg = new MessageContet { Body = MessageBodyValue.Text, Subject = MessageSubjectValue.Text }; string[] adresses = MessageEmailsValue.Text.Split(','); List <string> adressList = new List <string>(); foreach (string adr in adresses) { adressList.Add(adr.Trim(' ')); } EmailSendServiceClass.Send(new KeyValuePair <string, int>(SenderServis.Host, SenderServis.Port), author, adressList, msg, new SendEndWindow()); }
static public void Send(KeyValuePair <string, int> host, PersonMail author, List <string> adresses, MessageContet msg, IResult resultMsg) { using (SmtpClient client = new SmtpClient(host.Key, host.Value)) { client.EnableSsl = true; //подтверждаем шифрование client.Credentials = new NetworkCredential(author.Login, author.Password); //учетные данные //другие параметры из методички можно не включать using (MailMessage message = new MailMessage()) { message.From = new MailAddress(author.Email, author.Name); message.To.Add(new MailAddress(author.Email, author.Name)); message.Subject = msg.Subject; message.Body = msg.Body; message.IsBodyHtml = msg.IsBodyHTML; // message.Attachments.Add(new Attachment(file)) try { client.Send(message); resultMsg.ShowResult("Was sent!"); } catch (Exception error) { resultMsg.ShowResult(error.Message); } } } }