System.dll中出现'System.InvalidOperationException'类型的第一次机会异常

时间:2016-04-21 03:42:26

标签: c# textbox mailmessage

尝试向我的电子邮件发送TextBox值时,我一直收到此异常。这是我到目前为止的代码,我已经搞砸了很多。我不仅收到此消息,而且还没有收到此TextBox的电子邮件。我也在使用C#ASP.NET。单击按钮时,我也会收到消息。

protected void donateSubmit_onClick(object sender, EventArgs e)
{
    using (MailMessage message = new MailMessage())
    {
        message.To.Add(new MailAddress("jenlc0620@gmail.com"));
        message.CC.Add(new MailAddress("moeplamen@gmail.com"));

        message.Subject = "Charity Inquiry";
        message.Body = donateBox.Text.ToString();
        SmtpClient client = new SmtpClient("smtp.gmail.com", 456);
        client.UseDefaultCredentials = false;
        System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("email","password");

        client.Credentials = credentials;
        client.Host = "127.0.0.1";
        client.EnableSsl = true;
        try
        {
            client.Send(message);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);   //Should print stacktrace + details of inner exception

            if (ex.InnerException != null)
            {
                Console.WriteLine("InnerException is: {0}", ex.InnerException);
            }
        }
    }

    donateBox.Text=String.Empty;
}

0 个答案:

没有答案