我如何使用c#从asp.net中的.aspx页向我的gmail发送电子邮件 [英] How can i send an email into my gmail from an .aspx page in asp.net using c#
本文介绍了我如何使用c#从asp.net中的.aspx页向我的gmail发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用c#
推荐答案
该链接从asp.net中的.aspx页面向我的gmail发送电子邮件
http://www.4guysfromrolla.com/articles/072606-1.aspx
this link may help you
http://www.4guysfromrolla.com/articles/072606-1.aspx
尝试使用以下代码,希望它能工作.根据您的凭据更改凭据(用户名和密码)和收件人地址.
Try using the following code, hope it will work. Change credentials (UserName & Password) and receiver address according to yours.
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Host = "smtp.gmail.com";
client.Port = 587;
// setup Smtp authentication
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential("gmailusername@gmail.com", "gmailpassword");
client.UseDefaultCredentials = false;
client.Credentials = credentials;
MailMessage msg = new MailMessage();
msg.From = new MailAddress("gmailusername@gmail.com");
msg.To.Add(new MailAddress("xyz@gmail.com"));
msg.Subject = "This is a test Email subject";
msg.IsBodyHtml = true;
msg.Body = string.Format("<html><head></head><body>Test HTML Email</body>");
try
{
client.Send(msg);
//lblMsg.Text = "Your message has been successfully sent.";
}
catch (Exception ex)
{
//lblMsg.ForeColor = Color.Red;
//lblMsg.Text = "Error occured while sending your message." + ex.Message;
}
这篇关于我如何使用c#从asp.net中的.aspx页向我的gmail发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文