zoukankan      html  css  js  c++  java
  • C# System.Web.Mail.MailMessage 发邮件

    C# System.Web.Mail.MailMessage 发邮件

    新建控制台Console项目,然后添加 System.Web引用

    代码如下:

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Globalization;
    using System.IO;
    //using System.IO.Pipes;
    using System.Net;
    using System.Net.Mail;
    using System.Reflection;
    using System.Text;
    using System.Text.RegularExpressions;
    
    namespace LongtengSupremeConsole
    {
        class Program
        {        
            static void Main(string[] args)
            {
                System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
                mail.To = "test@qq.com";
                mail.From = "test@aliyun.com";
                mail.Subject = "测试邮箱";
                mail.BodyFormat = System.Web.Mail.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", mail.From); //邮箱登录账号  
                mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "*****"); //登录密码  
                mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);//端口  
                //mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");//SSL加密  
                System.Web.Mail.SmtpMail.SmtpServer = "smtp.aliyun.com";    //企业账号用smtp.exmail.qq.com  
                System.Web.Mail.SmtpMail.Send(mail);
                Console.WriteLine("邮件发送完成!!");
                Console.ReadKey();
            }
    }
    }
  • 相关阅读:
    nginx重启命令
    Java中Vector笔记
    JAVA中字符串比较equals()和equalsIgnoreCase()的区别
    HashMap和TreeMap的常用排序方法
    Logger用法
    HashMap和Hashtable的区别
    class.getDeclaredFields()与class.getFields()
    java中 文件压缩处理
    Java远程执行Shell命令
    python 学习笔记 redis操作
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/12015213.html
Copyright © 2011-2022 走看看