Yes I know it's very broad but I am relativity new to programming in C#. In my system there are a couple of text boxes and I want the information to be sent to my email when the user presses the button on my program.
Text box names:
textbox1
textbox2
Button name:
btnsend
Code so far:
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 WindowsFormsApplication1
{
public partial class form1 : Form
{
public form1()
{
InitializeComponent();
}
button1.Click += button1_Click;
private void button1_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage("myemail", "myemail2");
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("myemail");
mail.To.Add("myemail2");
mail.Subject = textBox1.Text;
mail.Body = textBox2.Text;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("myemail","myemailpassword");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("Email sent");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
The code is now trying to do what it is intended to do. I now get this error when I press button1: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated The server response was 5.5.1 Authentication required.