0

I keep getting this exception when trying to send a TextBox value to my email. This is the code I have so far and I have messed around with it a lot. I am not only getting this message but also I haven't received an email from this TextBox yet. I am using C# and ASP.NET as well. I also have the message to go when a button is clicked.

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;
}
hendryanw
  • 1,819
  • 5
  • 24
  • 39
Jennifer
  • 210
  • 1
  • 11
  • Where do you get the exception (which line)? What is the exception? Also, is this `WinForm` - Release built? – Ian Apr 21 '16 at 03:47
  • Have you tried with a fixed string instead of the one from the textbox? Try: `message.Body = "This is a test string...";` or the like... – Adam Calvet Bohl Apr 21 '16 at 03:56
  • I tried the fixed string and I got the same exception and no message in my email and I don't see what line it is. Is there a way to have the call stack print out the line? – Jennifer Apr 21 '16 at 04:10
  • 2
    Try the code in [this](http://stackoverflow.com/questions/9201239/send-e-mail-via-smtp-using-c-sharp) SO question. – Jeroen Heier Apr 21 '16 at 04:13
  • @Jennifer Did Jeroen's link solve your issue? – Rob Apr 21 '16 at 04:42

0 Answers0