如何使用Gmail的SMTP在ASP.NET表单 [英] How to use gmail SMTP in ASP.NET form
问题描述
我是一个新手的ASP和我故障排除工作的一种形式。我们都没有这里的ASP专家为我们使用PHP。但我对PHP的经验底部为好,大多是单独的HTML / CSS工作。我目前的形式凭据如下:
rotected子SubmitForm_Click(BYVAL发件人为对象,BYVAL E上System.EventArgs)
如果没有Page.IsValid然后退出小组 昏暗SendResultsTo作为字符串=电子邮件至
昏暗smtpMailServer作为字符串=邮件服务器
昏暗smtpUsername作为字符串=电子邮件用户名
昏暗smtpPassword作为字符串=密码
昏暗MailSubject作为字符串=表单结果
我如何去制作这个表格发送到Gmail地址?我知道我必须包括端口(587)的地方,但不能揣摩出,因为这种形式不匹配的任何其他形式的我见过的语法。任何帮助将大大AP preciated!
保护无效的SendMail()
{
味精MAILMESSAGE新= MAILMESSAGE();
System.Net.Mail.SmtpClient客户端=新System.Net.Mail.SmtpClient();
尝试
{
msg.Subject =添加主题;
msg.Body =添加电子邮件正文部分;
msg.From =新的MailAddress(有效的电子邮件地址);
msg.To.Add(有效的电子邮件地址);
msg.IsBodyHtml =真;
client.Host =smtp.gmail.com;
System.Net.NetworkCredential basicauthenticationinfo =新System.Net.NetworkCredential(有效的电子邮件地址,密码);
client.Port = int.Parse(587);
client.EnableSsl = TRUE;
client.UseDefaultCredentials = FALSE;
client.Credentials = basicauthenticationinfo;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(MSG);
}
赶上(异常前)
{
log.Error(ex.Message);
}
}
I am a ASP novice and am troubleshooting a form for work. None of us here are ASP experts as we use PHP. But I am on the bottom of PHP experience as well, mostly working with HTML/CSS alone. My current forms credentials look like:
rotected Sub SubmitForm_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsValid Then Exit Sub
Dim SendResultsTo As String = "email to"
Dim smtpMailServer As String = "email server"
Dim smtpUsername As String = "email username"
Dim smtpPassword As String = "password"
Dim MailSubject As String = "Form Results"
How would I go about making this form send to a Gmail address? I know I must include the port (587) somewhere, but cannot figure out where, as this form doesn't match the syntax of any other forms I have seen. Any help would be greatly appreciated!
protected void SendMail()
{
MailMessage msg = new MailMessage();
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
try
{
msg.Subject = "Add Subject";
msg.Body = "Add Email Body Part";
msg.From = new MailAddress("Valid Email Address");
msg.To.Add("Valid Email Address");
msg.IsBodyHtml = true;
client.Host = "smtp.gmail.com";
System.Net.NetworkCredential basicauthenticationinfo = new System.Net.NetworkCredential("Valid Email Address", "Password");
client.Port = int.Parse("587");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = basicauthenticationinfo;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(msg);
}
catch (Exception ex)
{
log.Error(ex.Message);
}
}
这篇关于如何使用Gmail的SMTP在ASP.NET表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!