本文介绍了如何修复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;
}
解决方案




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;
            }
解决方案




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

07-17 12:16
查看更多