K
K
Konstantin Kavensky2017-08-17 15:21:27
.NET
Konstantin Kavensky, 2017-08-17 15:21:27

Why is sending mail not working?

Actually there is a form with data for sending letters, gmail and Yandex does not work, prescribed different smtp server - gives "Failed to send e-mail" An unhandled exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
Actually, the code

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;


namespace mailbrif
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Отправка сообщения
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            //Создаём mail и туда берём всю информацию из textбоксов
            MailMessage mail = new MailMessage(from.Text, to.Text, subject.Text, body.Text);
            SmtpClient client = new SmtpClient(smtp.Text);
          client.Port = 465;
            client.Credentials = new System.Net.NetworkCredential(username.Text, password.Text);
          client.EnableSsl = true;
          client.Send(mail);
            MessageBox.Show("Письмо отправлено!", "Успех!", MessageBoxButtons.OK);


        }
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question