zoukankan      html  css  js  c++  java
  • C#发送电子邮件

    frombegintoend 原文 C#发送电子邮件

        using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Text;  
    using System.Net.Mail;  
    using System.Net.Mime;  
    using System.IO;  
    using System.Net;  
      
    namespace _11发送电子邮件  
    {  
        class Program  
        {  
            static void Main(string[] args)  
            {  
                Console.WriteLine("用户名");  
                string uid = Console.ReadLine();//发件人邮箱地址@符号前面的字符tom@dddd.com,则为"tom"  
                Console.WriteLine("密码");//发件人邮箱的密码  
                string pwd = Console.ReadLine();  
                for (int i = 0; i < 20; i++) //连发20封,嘿嘿  
                {  
                    MailAddress from = new MailAddress("发件人的邮箱地址");  
                    MailAddress to = new MailAddress("收件人的邮箱地址");  
                    MailMessage mailMessage = new MailMessage(from, to);  
                    mailMessage.Subject = "Test";//邮件主题  
                    mailMessage.Body = "Hello, world!!";//邮件正文  
      
                    //添加附件  
      
                    string file1 = "test.txt";  
                    Attachment attachment1 = new Attachment(file1, MediaTypeNames.Text.Plain);  
                    //为附件天剑时间信息  
                    ContentDisposition disposition1 = attachment1.ContentDisposition;  
                    disposition1.CreationDate = File.GetCreationTime(file1);  
                    disposition1.ModificationDate = File.GetLastWriteTime(file1);  
                    disposition1.ReadDate = File.GetLastAccessTime(file1);  
                    mailMessage.Attachments.Add(attachment1);  
      
                    string file2 = "test.doc";  
                    Attachment attachment2 = new Attachment(file2);  
                    //为附件添加时间信息  
                    ContentDisposition disposition2 = attachment2.ContentDisposition;  
                    disposition2.CreationDate = File.GetCreationTime(file2);  
                    disposition2.ModificationDate = File.GetLastWriteTime(file2);  
                    disposition2.ReadDate = File.GetLastAccessTime(file2);  
                    mailMessage.Attachments.Add(attachment2);  
      
                    //实例化SmtpClient  
                    SmtpClient smtpClient = new SmtpClient("smtp.yeah.net", 25);  
                    //设置验证发件人身份的凭据  
                    smtpClient.Credentials = new NetworkCredential(uid, pwd);  
                    //发送  
                    smtpClient.Send(mailMessage);  
      
                    Console.WriteLine("OK - [{0}]",i);  
                }  
      
                Console.ReadKey();  
            }  
        }  
    }  
  • 相关阅读:
    Linux常用命令ifconfig的相关信息
    搭建路由实例
    httpclient以json形式参数调用http接口并解析返回的报文
    思考(机遇)
    php 对齐方法
    RequireJS简单介绍即使用
    一周小结(2016-06-06~2016-06-12)
    git介绍及使用
    一周小结(2016-05-30~2016-06-04)
    [转] Mou 一个Markdown工具 语法规则文档(最后)
  • 原文地址:https://www.cnblogs.com/arxive/p/6147806.html
Copyright © 2011-2022 走看看