I am trying to send an email c#, using the using System.Net.Mail;
However I am getting the following exception message:
This is my send email code:
MailMessage mail = new MailMessage();
smtpServer = new SmtpClient();
smtpServer.Host = "smtp.gmail.com";
mail.From = new MailAddress("[email protected]");
mail.To.Add(new MailAddress(textBox7.Text));
mail.Subject = "Your User ID and Password For etc company";
mail.Body = "Your ID IS:" + textBox1.Text + " Your Password Is: " +
textBox2.Text;
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential();
smtpServer.EnableSsl = true;
smtpServer.Send(mail);
MessageBox.Show("Mail Successfully Sent To " + textBox7.Text, "Message",
MessageBoxButtons.OK, MessageBoxIcon.Information);
The constructor new MailAddress
does not accept an empty string. The issue is most likely that your textBox7.Text
is an empty string.