Cześć. Chcę zrobić klienta pocztowego. Mam tylko pewien problem, mianowicie cały czas wyskakuje mi błąd przy client.Send(message); nie wiem dlaczego. Przeglądałem różne fora ale nie znalazłem rozwiązania problemu. Na dole umieszczam kod, który napisałem. Proszę o pomoc i dzięki za odpowiedzi.
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;
using System.Net.Mail;
namespace Aplikacja_gmail_testy
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string login = textBox1.Text;
string haslo = maskedTextBox1.Text;
string adresat = textBox2.Text;
string temat = textBox3.Text;
string tresc = textBox4.Text;
MailAddress to = new MailAddress(adresat);
MailAddress from = new MailAddress(login);
MailMessage message = new MailMessage(from, to);
message.Subject = temat;
message.Body = tresc;
using (SmtpClient client = new SmtpClient("smtp.gmail.com", 587))
{
client.Credentials = new NetworkCredential(login, haslo);
client.EnableSsl = true;
client.Send(message);
}
}
}
}