本文介绍了发送电​​子邮件按钮单击ASP.net C#后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我试图在Asp.net按钮点击后发送电子邮件上午

Hi i am trying to send am email after Button click in 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

推荐答案

这code应该工作:

foreach(string email in emailArray)
{
     SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
     smtp.UseDefaultCredentials = false;
     smtp.Credentials = new NetworkCredential("[email protected]", "xxxxxxxxx");
     smtp.EnableSsl = true;

     MailMessage msg = new MailMessage("[email protected]", email); 
     msg.Subject = "Test1";
     msg.Body = "Test2";

     smtp.Send(msg);
 }

有安全设置,你应该在你的Gmail帐户关闭。

There is security setting which you should turn off in your gmail account.

编辑:就像我说的,你应该在Gmail帐户关闭安全设置!如果该链接不帮你只是谷歌的例外!检查!或者这

Like I said you should TURN OFF security setting in gmail account ! If this link doesn't help you just google the exception ! Check the Link ! Or this LINK

这篇关于发送电​​子邮件按钮单击ASP.net C#后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 23:55