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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…