zq9955
我想摘星辰
2020-10-29 11:28

引发的异常:“System.Web.HttpException”(位于 System.Web.dll 中)

  • c#
  • asp.net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            //发件人
            const string sendAddress = "serveripchange.com";
            // const string sendAddress = "3461094650@qq.com";
            //发件人密码
            const string sendPassword = "autoview123";
            //const string sendPassword = "xxxxxx";
            //收件人
            const string receiveAddress = "zhaixingchen_0523@163.com";

            System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
            try
            {
                mail.From = sendAddress;
                mail.To = receiveAddress;
                mail.Subject = "whl测试发送邮件2-26-1";
                mail.BodyFormat = System.Web.Mail.MailFormat.Html;
                mail.Body = "whl发送的测试邮件" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
                mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", sendAddress); //set your username here 发件人邮箱
                mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", sendPassword); //set your password here 发件人邮箱密码
                mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);//发送端口号
                mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");//是否启用ssl

                //需要引用组件System.Web
                System.Web.Mail.SmtpMail.SmtpServer = "smtp.163.com";
               // System.Web.Mail.SmtpMail.SmtpServer = "smtp.qq.com";
                System.Web.Mail.SmtpMail.Send(mail);

                Console.WriteLine("发送邮件成功");
            }
            catch (Exception ex)
            {
                var exg = ex.InnerException ?? ex;
                string msg = exg.ToString();
                Console.WriteLine(msg);
            }

        }
    }
}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐