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下载:
        在这里下载示例程序以及源代码

  • 相关阅读:
    Spring_3.1
    handler发消息的形式
    css元素排列
    利用Socket远程发送文件
    jtree添加节点
    url传参中文乱码
    struts action和jsp之间的传值
    Struts 404 The requested resource is not available
    tomcat server需要重启的时刻
    c++获取系统时间(引用别人的博文)
  • 原文地址:https://www.cnblogs.com/zhouyinhui/p/426057.html
Copyright © 2011-2022 走看看