如何修复C#中发送电子邮件问题? [英] How Do I Fix Sending Email Problem In C# ?

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

问题描述

大家好,

i尝试简单开发网站,我需要在其中添加发送邮件



i尝试多种格式的代码,但我仍然遇到同样的问题

我面临的问题是:

在Chrome浏览器中:根据验证程序,远程证书无效。

在Firefox& Internet Explorer :发送邮件失败。



这是代码,我在youtube上看到它和写它的人一起工作,但我不知道是什么问题与我的项目..



代码:



 MailMessage msg =  new  MailMessage(); 
MailAddress to = new MailAddress(Label24.Text.ToString(), Trainig管理系统);
MailAddress 来自 = new MailAddress(Label15.Text.ToString());
msg.To.Add(to);
msg.From = 来自;
msg.Subject = Label20.Text.ToString();
msg.Body = Label23.Text.ToString();
msg.IsBodyHtml = true ;
msg.SubjectEncoding = System.Text.Encoding.UTF8;

// 读取邮件信息smtp简单传输协议
SmtpClient client = new SmtpClient();
client.Host = smtp.gmail.com; // google smtp setting
client.Port = 587 ;

// 获取'from'地址详细信息(用户名+密码)
System.Net.NetworkCredential myaccount = new NetworkCredential(Label15.Text.ToString(),TextBox1.Text.ToString());
client.Credentials = myaccount;
client.EnableSsl = true ; // encription,使其安全(发件人信息)
client.UseDefaultCredentials = ;


尝试
{
client.Send(msg);
Server.Transfer( end_message.aspx);
}
catch (例外情况)
{
Label19.Text = ex.Message;
}

解决方案

根据错误消息远程证书根据验证程序无效。在上面的一条评论中,你可能想要执行这些诊断步骤 [ ^ ]。还要确保系统的日期和时间正确无误。



希望这会有所帮助。


请删除Google身份验证两步验证,然后重试..


如果仍然坚持尝试这些,



http://i.stack.imgur.com/SSA0j.png



http://stackoverflow.com/questions/20906077/gmail-error-所述-SMTP-服务器需要-A-安全连接或 - 所述客户端 - 是 - 不

Hi All,
i trying to simple develop website and i need to add sending email in it

i try many format of codes, but still i get same problem
the problem that I face says:
in Chrome browser : The remote certificate is invalid according to the validation procedure.
in Firefox & Internet Explorer : Failure sending mail.

This is the code ,, and i saw that in youtube and it is working with the person who write it ,, but I don't know what is the problem with my project ..

The Code :

MailMessage msg = new MailMessage();
            MailAddress to = new MailAddress(Label24.Text.ToString(), " Trainig Management System");
            MailAddress from = new MailAddress(Label15.Text.ToString());
            msg.To.Add(to);
            msg.From = from;
            msg.Subject = Label20.Text.ToString();
            msg.Body = Label23.Text.ToString();
            msg.IsBodyHtml = true;
            msg.SubjectEncoding = System.Text.Encoding.UTF8;

            // to read mail information smtp simple transfer protocol
            SmtpClient client = new SmtpClient();
            client.Host = "smtp.gmail.com";   // google smtp setting
            client.Port = 587;

            // to get the 'from' address details ( user name + password) 
            System.Net.NetworkCredential myaccount = new NetworkCredential(Label15.Text.ToString(), TextBox1.Text.ToString());
            client.Credentials = myaccount;
            client.EnableSsl = true;  // encription, make it secure (the sender infromation) 
            client.UseDefaultCredentials = false;


            try
            {
                client.Send(msg);
                Server.Transfer("end_message.aspx", true);
            }
            catch (Exception ex)
            {
                Label19.Text = ex.Message;
            }

解决方案

As per the error message "The remote certificate is invalid according to the validation procedure." in one of your comments above, you may want to perform these diagnostic steps[^]. Also ensure that the system's date and time are correct.

Hope this helps.


Please remove Google authentication 2-step verification and try again ..


if still persist try these,

http://i.stack.imgur.com/SSA0j.png

http://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not


这篇关于如何修复C#中发送电子邮件问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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