参数“地址”不能为空字符串

时间:2019-01-12 13:07:50

标签: c# windows email exception gmail

我正在尝试使用System.Net.Mail发送电子邮件c#; ​​

但是我收到以下异常消息:

  

这是我的发送电子邮件代码:

MailMessage mail = new MailMessage();

smtpServer = new SmtpClient();
smtpServer.Host = "smtp.gmail.com";

mail.From = new MailAddress("example@gmail.com");

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);

1 个答案:

答案 0 :(得分:0)

构造函数new MailAddress不接受空字符串。问题很可能是您的textBox7.Text是一个空字符串。