Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
92 views
in Technique[技术] by (71.8m points)

html - Trying to configure Web site form on asp.net

I am writing a web page with asp.net and am having problems with a web form. My intent is to have the form send an email via gmail.com. I ran into a couple of situations where I received warnings that the sign in attempts were blocked. I think I have configured security so that it only requires log in ID and password, but I can't get it to take. Here is my asp.c code:

    protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        try
        { 
            // Form the mail message
            MailMessage mailMessage = new MailMessage();
            // set the from address
            mailMessage.From = new MailAddress(TextBoxEMail.Text, TextBoxName.Text + " - " + TextBoxCallsign.Text);
            // set the to address
            mailMessage.To.Add("[email protected]");
            // set the subject
            mailMessage.Subject = "Web site submission";
            // set the message body
            mailMessage.Body =  TextBoxComment.Text;
            mailMessage.IsBodyHtml = true;

            // create the smtpclient
            SmtpClient smtp = new SmtpClient();
            // set the username and password
            smtp.Credentials = new NetworkCredential("[email protected]", "poindexter");
            smtp.Port = 465;  //25; //465;  //587;
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.Host= "smtp.gmail.com";
            smtp.Send(mailMessage);

            // write to Label to inform user of success.
            LabelSuccess.Text = "Email Sent";
        }// try
        catch (Exception ex)
        {   // write error code to label for debug purposes
            LabelSuccess.Text = ex.ToString();
        }// catch
    }// ButtonSubmit_Click

I have been playing around with host configuration (smtp.host) and smtp port, and have had no success. Any ideas?

Mike

question from:https://stackoverflow.com/questions/65877887/trying-to-configure-web-site-form-on-asp-net

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...