Net.Mail”我使用“System.Web.Mail”使用C#通过SMTP发送电子邮件,代码如下。它正在工作,但我认为它已经过时了,所以我想使用“System.Net.Mail”我如何使用System;更改或转换以下代码?使用系统数据;使用系统集合;使用System.ComponentModel;使用System.Configuration使用System.Drawing;使用System.Web;使用System.Web.SessionState;使用System.Web.UI;使用System.Web.UI.WebControls;使用System.Web.UI.HtmlControls;使用System.Web.Mail;使用System.Net;//(...)MailMessagemail=newMailMessage();mail.To=s.EmailFirst;mail.Cc=s.EmailSecond;mail.Bcc=ConfigurationManager.AppSettings["mailConfirmeMe"];邮件.Bcc=ConfigurationManager.AppSettings["mailConfirmeTheir"];mail.From=ConfigurationManager.AppSettings["FromEmail"];mail.Subject="对象:确认";mail.BodyFormat=MailFormat.Html;mail.Body="这是我的测试邮件正文";mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1");//基本认证mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","myUserName@domain.com");//在这里设置我的用户名mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","##########");//在这里设置我的密码SmtpMail.SmtpServer="000.000.0.0";//设置我的服务器电子邮件SmtpMail.Send(mail);//(...)这是我的答案/解决方案::::::::::::::::::::::::::::::::::::::::::::::::::::::::我尝试使用以下新代码:它有效,太棒了......根据您的说法,这段代码是否正确?这是答案/答案:::::::::::::::::::::::::::::::::usingSystem.Net.Mail;//.....protectedvoidOkButton_Click(对象发件人,System.EventArgse){MailAddressfrom=newMailAddress(ConfigurationManager.AppSettings["FromEmail"]);MailAddressto=newMailAddress(s.EmailFirst);MailMessagemessage=newMailMessage(from,to);message.Subject="OBJET:CONFIRMATION";message.Body=@"thisismytestemailbody";message.BodyEncoding=System.Text.Encoding.UTF8;//添加抄送收件人。MailAddresscopy=newMailAddress(s.EmailSecond);message.CC.Add(复制);MailAddressbcc=newMailA地址(ConfigurationManager.AppSettings[“mailConfirmeMe”]);message.Bcc.Add(密件抄送);MailAddressbcc2=newMailAddress(ConfigurationManager.AppSettings["mailConfirmeTheir"]);message.Bcc.Add(bcc2);//设置我的服务器邮箱/*stringserver="000.000.0.0";//设置我的服务器电子邮件SmtpClientclient=newSmtpClient(server);SmtpClient.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1");//基本认证SmtpClient.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","myUserName@domain.com");//在这里设置我的用户名SmtpClient.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","##########");//在这里设置我的密码*/SmtpClientclient=newSmtpClient();client.Host="000.000.0.0";//设置我的服务器电子邮件client.Credentials=newSystem.Net.NetworkCredential("myUserName@domain.com","##########");//在这里设置我的用户名和密码//client.Credentials=CredentialCache.DefaultNetworkCredentials;Console.WriteLine("正在使用SMTP主机{1}向{0}发送电子邮件消息。",to.Address,message.CC.ToString(),message.Bcc.ToString());尝试{客户端。发送(消息);}catch(Exceptionex){Console.WriteLine("在CreateBccTestMessage():{0}",ex.ToString());}//...}看看这个:SmtpClient.SendSmtpClient替换SmtpMail几乎一模一样以上是C#学习教程:HowItransformmyC#code:System.Web.Mail"transformby"System.Net.Mail》分享了全文,如果对你有用,需要了解更多C#学习教程,希望大家多多关注——本文收集自网络,不代表立场。如有涉及侵权,请点击维权联系管理员删除,如需转载请注明出处:
