[英]Send Email After Button Click in ASP.net C#
Hi i am trying to send am email after Button click in Asp.net.嗨,我正在尝试在 Asp.net 中单击按钮后发送电子邮件。
The emails to send the email to will be retrieved from a query.将从查询中检索要发送电子邮件的电子邮件。
string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlDataReader reader;
string sendMessage = "SELECT aspnet_Membership.Email FROM aspnet_Membership join User_Profile on User_Profile.UserId = aspnet_Membership.UserId JOIN Project_List on Project_List.ProfileId = User_Profile.ProfileId WHERE Project_List.ProfileId = 1";
using (SqlConnection myConnection = new SqlConnection(connectionString))
{
myConnection.Open();
SqlCommand myCommand = new SqlCommand(sendMessage, myConnection);
ArrayList emailArray = new ArrayList();
reader = myCommand.ExecuteReader();
while (reader.Read())
{
emailArray.Add(reader["email"]);
}
foreach (string email in emailArray)
it doesn't come up with any errors, and i don't receive any emails它没有出现任何错误,我也没有收到任何电子邮件
This code should work:此代码应该工作:
foreach(string email in emailArray)
{
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("tayyib@gmail.com", "xxxxxxxxx");
smtp.EnableSsl = true;
MailMessage msg = new MailMessage("tayyib@gmail.com", email);
msg.Subject = "Test1";
msg.Body = "Test2";
smtp.Send(msg);
}
There is security setting which you should turn off in your gmail account.您应该在 Gmail 帐户中关闭安全设置。
EDIT: Like I said you should TURN OFF security setting in gmail account !编辑:就像我说的,您应该关闭 gmail 帐户中的安全设置! If this link doesn't help you just google the exception !
如果此链接对您没有帮助,请使用谷歌搜索异常! Check the Link !
检查链接! Or this LINK
或者这个链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.