I can't seem to get this to work. I'm trying to make something to send email from a desktop application, but I keep getting the errors
An unhandled exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
Additional information: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. l9sm2010572yhb.26 - gsmtp"
When using 587 for the port, and I get this
A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll An unhandled exception of type 'System.Net.Mail.SmtpException' occurred in System.dll Additional information: The operation has timed out.
When using 465 as the port.
Here's the code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication15
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void genuineButton1_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
private void fusionButton1_Click(object sender, EventArgs e)
{
String Sender = textBox1.Text;
String Pass = textBox2.Text;
String Recepient = textBox3.Text;
String Subject = textBox4.Text;
String Body = richTextBox1.Text;
MailMessage message = new MailMessage();
message.From = new MailAddress(String.Copy(Sender));
message.To.Add(new MailAddress(String.Copy(Recepient)));
message.Subject = String.Copy(Subject);
message.Body = String.Copy(Body);
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 465;
client.Send(message);
System.Net.NetworkCredential netCre = new System.Net.NetworkCredential(String.Copy(Sender), String.Copy(Pass));
client.UseDefaultCredentials = false;
client.EnableSsl = true;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
Any Ideas?