Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29758

How do I make an ASP.NET C# email app for user's to send feedback from my website?

$
0
0

I'm new to ASP.NET C# and I've been trying to figure out how to do this for a long time. I found a video on Youtube - https://www.youtube.com/watch?v=Baw6O3ME8Go - that shows how to make a simple email app in ASP.NET C#. However, when I run the script, I keep getting different errors. This is what my code looks like:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;

namespace my_site
{
    public partial class contact : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void send_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage message = new MailMessage(txtTo.Text, txtFrom.Text, txtSubject.Text, txtBody.Text);
                message.IsBodyHtml = true;
                SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                client.Credentials = new System.Net.NetworkCredential("jameshollan79@gmail.com", "************");
                client.EnableSsl = false;
                client.Send(message);
                status.Text = "Thanks for the feedback!";
            }
            catch (Exception ex)
            {
                status.Text = ex.StackTrace;
            }
        }
    }
}

One error message showed that it was on line 22 , which is just "{" after the try. Another error said that it was line 33 which is "status.Text = ex.StackTrace;". Another error that it comes up with says that it is line 28 that says "client.Send(message);".

For that last one, the stacktrace said

"at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)

at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode)

at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception)

at System.Net.Mail.SmtpClient.Send(MailMessage message)

at my_site.contact.send_Click(Object sender, EventArgs e)

in C:\Users\Administrator\Desktop\my_site\my_site\contact.aspx.cs:line 28"

Is there something that I'm doing wrong? Or is there a better way to do it?

If it helps, I do have a bit of experience in Classic ASP.


Viewing all articles
Browse latest Browse all 29758

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>