Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Net.Mail;
- using System.Net;
- using System.Runtime.InteropServices;
- namespace FinalProject
- {
- public partial class EmailClient : Form
- {
- public EmailClient()
- {
- InitializeComponent();
- }
- private void txtMail_Enter(object sender, EventArgs e)
- {
- if (txtMail.Text == "Кому") {
- txtMail.Clear();
- txtMail.ForeColor = Color.FromArgb(83, 179, 233);
- }
- }
- private void txtMail_Leave(object sender, EventArgs e)
- {
- if (txtMail.Text == "") {
- txtMail.ForeColor = Color.FromArgb(200, 200, 200);
- txtMail.Text = "Кому";
- }
- }
- private void txtSub_Enter(object sender, EventArgs e)
- {
- if (txtMail.Text == "Тема")
- {
- txtMail.Clear();
- txtMail.ForeColor = Color.FromArgb(83, 179, 233);
- }
- }
- private void txtSub_Leave(object sender, EventArgs e)
- {
- if (txtMail.Text == "")
- {
- txtMail.ForeColor = Color.FromArgb(200, 200, 200);
- txtMail.Text = "Тема";
- }
- }
- private void txtMess_Enter(object sender, EventArgs e)
- {
- if (txtMail.Text == "Текст")
- {
- txtMail.Clear();
- txtMail.ForeColor = Color.FromArgb(83, 179, 233);
- }
- }
- private void txtMess_Leave(object sender, EventArgs e)
- {
- if (txtMail.Text == "")
- {
- txtMail.ForeColor = Color.FromArgb(200, 200, 200);
- txtMail.Text = "Текст";
- }
- }
- private void btnSend_Click(object sender, EventArgs e)
- {
- if (txtMail.Text == "" || txtMail.Text == "Кому" || txtSub.Text == "" || txtSub.Text == "Тема") {
- MessageBox.Show("Пожалуйста, введите почту получателя и заголовок темы", "Сообщение не отправлено", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else {
- string from, to, password, messageBody;
- MailMessage message = new MailMessage();
- from = "obechekopm@gmail.com";
- to = txtMail.Text;
- password = "LycanMidas3002";
- messageBody = txtMess.Text;
- message.To.Add(to);
- message.From = new MailAddress(from);
- message.Body = "<br>Текст сообщения: " + messageBody;
- message.Subject = txtSub.Text;
- message.IsBodyHtml = true;
- SmtpClient smtp = new SmtpClient("smtp.gmail.com");
- smtp.EnableSsl = true;
- smtp.Port = 587;
- smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
- smtp.Credentials = new NetworkCredential(from, password);
- try
- {
- smtp.Send(message);
- DialogResult code = MessageBox.Show("Письмо успешно отправлено", "Письмо отправлено", MessageBoxButtons.OK, MessageBoxIcon.Information);
- if (code == DialogResult.OK)
- {
- txtMail.Clear();
- txtSub.Clear();
- txtMess.Clear();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement