如何使用ASP.NET发送电子邮件? [英] How to send email using ASP.NET?

查看:76
本文介绍了如何使用ASP.NET发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我在这部分中收到错误消息SMTP服务器需要安全连接或客户端未经过身份验证。浏览器是指向

Hi guys!

I got an error in this part saying, "The SMTP server requires a secure connection or the client was not authenticated. " the browser is pointing at

smtp.Send(fromAddress, toAddress, subject, body);

。这是错误的地方。但我认为不是。



这是我的代码:

. It is where the error. But I think it is not.

Here is my code:

protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
    {
            
            GeneratePass(); //Generate System ID
            s = WebConfigurationManager.ConnectionStrings["amicassa"].ConnectionString;
            amicasaCon = new SqlConnection(s);
            amicasaCon.Open();

            SqlCommand cadd = new SqlCommand("Update users set system_id ='"+oldpassword.Text+"' WHERE username = '"+username.Text+"' ", amicasaCon);
            SqlDataReader rcd = cadd.ExecuteReader();
            rcd.Close();
            amicasaCon.Close();
            try
            {
                //here on button click what will done 
            SendMail();
            newpassword.Text = "";
            oldpassword.Text = "";
            Response.Redirect("ChangePassword.aspx");
            
        }
        catch (Exception) { }

       
    }

    protected void SendMail()
    {
        // Gmail Address from where you send the mail
        var fromAddress = "xxxxx@gmail.com";
        // any address where the email will be sending
        var toAddress = newpassword.Text.ToString();
        //Password of your gmail address
        const string fromPassword = "xxxxxxxx";
        // Passing the values and make a email formate to display
        string subject = oldpassword.Text.ToString();
        string body = "From: ADMIN "+"\n";
        body += "Email: " + newpassword.Text + "\n";
        body += "System ID : " + oldpassword.Text + "\n";
        body += "Please DO NOT REPLY" + "\n";
        // smtp settings
        var smtp = new System.Net.Mail.SmtpClient();
        {
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
            smtp.Timeout = 20000;
        }
        // Passing values to smtp object
        smtp.Send(fromAddress, toAddress, subject, body);
    }

推荐答案

请参阅:

http://msdn.microsoft.com/en-us/library/system。 net.mail.smtpclient.enablessl%28v = vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system。 net.mail.smtpclient.credentials%28v = vs.110%29.aspx [ ^ ]。



-SA
Please see:
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.enablessl%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.credentials%28v=vs.110%29.aspx[^].

—SA


请通过以下链接



^ ]



http://asp.net-tutorials.com/misc/sending-mails/ [ ^ ]
please go through below link

Send Mail / Contact Form using ASP.NET and C#[^]

http://asp.net-tutorials.com/misc/sending-mails/[^]


您当前的SMTP设置似乎不正常。

在您的情况下 SSL已启用 STMP端口应为: 465



您可以在下一个链接中看到有关发送电子邮件的详细信息:/ b $ b https://support.google.com/mail/answer/78775?hl=en [ ^ ]
It seems that your current SMTP settings are not OK.
In your case for SSL Enabled the STMP port should be: 465

You could see details about sending email by using "gmail" settings problems and solutions at the next links:
https://support.google.com/mail/answer/78775?hl=en[^]


这篇关于如何使用ASP.NET发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆