zoukankan      html  css  js  c++  java
  • 用CDO.Message打造邮件发送程序

    用CDO.Message打造邮件发送程序
                    电子科技大学软件学院03级2班 周银辉

    1,关于System.Net.Mail:
        首先,不要寄希望于.net中的该名字空间(或其他旧版的名字空间),因为它不提供密码验证,这样你就使用不了邮件服务器。我们将使用CDO,在C:\WINDOWS\system32\下有个叫cdosys.dll的动态链接库文件,将它复制出来,并在你的程序中引用它。

    2,关于邮件服务器:
        大家一定听说过Pop3,Smtp之类的名词,这是两种类型的邮件服务器,能够让你注册并使用他们邮件服务的大大小小的网站都有他们自己的邮件服务器,但并非每个都那么慷慨地免费提供给我们的这个小程序使用,Yahoo!不可以,但163的可以,也就是说,为了完成我们这个程序,你应该注册一个163邮件或找到其他免费的。我们假设你的邮件地址是"abc@163.com",密码为"yourpassword"

    3,CDO.Message对象:
        代表了我们要发送的邮件对象。CDO.Message msg = new Message();
        msg.Form:发件人邮件地址
        msg.To:收件人邮件地址
        msg.Subject:邮件标题
        msg.HtmlBody:邮件主体,比如"<html><body>" + "邮件信息" + "</body></html>";
        msg.AddAttachment():添加附件
        msg.Send():发送邮件
    4,其他设置:
     1   CDO.IConfiguration iConfg = msg.Configuration;
     2                 ADODB.Fields oFields = iConfg.Fields;
     3 
     4                 oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2;
     5                 oFields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = "abc@163.com";
     6                 oFields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value = "abc@163.com";
     7                 oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value = "abc";
     8                 oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = "yourpassword";
     9                 oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1;
    10                 oFields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value = 0x0804;
    11                 oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = "smtp.163.com";
    12 
    13                 oFields.Update();
    14                 this.oMsg.BodyPart.Charset = "gb2312";
    15                 this.oMsg.HTMLBodyPart.Charset = "gb2312";

    5,成果:

    sendMail_pic.bmp

    6.Demo下载:
        在这里下载示例程序以及源代码

  • 相关阅读:
    操作系统基础知识与常见问题记录
    String
    Function
    HelloWorld
    替换空格
    二维数组中的查找
    建造者模式(Builder Pattern)
    单例模式(Singleton Pattern)
    工厂方法(Factory Pattern)
    设计模式概述
  • 原文地址:https://www.cnblogs.com/zhouyinhui/p/426057.html
Copyright © 2011-2022 走看看