我想在(c/s)winfrom中实现发送email,但要满足以下要求:
1.要利用指定的服务器的iis中的smtp来发送。
2.不能用自己本机的web服务,也就是说:把本机的iis给关掉(比如有些机器没有装iis)再来发送。
3.还有解决解析邮件域名问题。请各位高手们给点例子或参考资料,谢谢......

解决方案 »

  1.   

    Jmail说明下载:
      英文原版:http://www.ajiang.net/luntan/w3jmail4.pdf
      翻译后的:http://www.ajiang.net/luntan/w3jmail4_cn.pdf
      V3.7中文:http://www.ajiang.net/luntan/w3JMial37.pdf
      

  2.   

    为什么用Jmail,不能自己写呢?我想楼上的想要的不是这个。帮着顶。
      

  3.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Web.Mail;
    using CDO;namespace SendMail
    {
    /// <summary>
    /// 这个实例演示通过两种方式发送电子邮件(第一种使用MailMessage对象)
    /// (第二种使用了SmtpMail类)
    /// 第三个实例演示了附件的发送方法
    /// </summary>
    public class SendingMail : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.TextBox fromAddress;
    protected System.Web.UI.WebControls.TextBox sendToAddress;
    protected System.Web.UI.WebControls.TextBox messageSubject;
    protected System.Web.UI.WebControls.TextBox fileNameToAttach;
    protected System.Web.UI.WebControls.Button SendMessageNoMessageObj;
    protected System.Web.UI.WebControls.Button SendMessageWithFile;
    protected System.Web.UI.WebControls.TextBox SMTPServerName;
    protected System.Web.UI.WebControls.Label statusLabel;
    protected System.Web.UI.WebControls.TextBox messageBody;
    protected System.Web.UI.WebControls.Button SendMessage;

    private void Page_Load(object sender, System.EventArgs e)
    {


    } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
    this.SendMessage.Click += new System.EventHandler(this.SendMessage_Click);
    this.SendMessageNoMessageObj.Click += new System.EventHandler(this.SendMessageNoMessageObj_Click);
    this.SendMessageWithFile.Click += new System.EventHandler(this.SendMessageWithFile_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion
    /// <summary>
    /// 使用MailMessage对象
    /// </summary>
    private void SendMessage_Click(object sender, System.EventArgs e)
    {
    /// <summary>
    /// 创建一个名字为MailMessage的对象</summary>
    MailMessage myMail = new MailMessage();
    /// <summary>
    /// 设置发送者电子邮件</summary>
    /// <value>
    /// 邮件地址必须是可以可以被中继的mail服务器</value>
    myMail.From= fromAddress.Text;
    /// <summary>
    /// 设置接收者电子邮件</summary>
    /// <value>
    /// 你想发送到的邮件地址.</value>
    myMail.To=sendToAddress.Text;
    /// <summary>
    /// 设置电子邮件主题</summary>
    /// <value>
    /// 电子邮件主题</value>
    myMail.Subject=messageSubject.Text;
    /// <summary>
    /// 设置电子邮件内容</summary>
    /// <value>
    /// 可以设置内容格式,可以是Text或者Html</value>
    myMail.Body=messageBody.Text;
    /// <summary>
    /// 设置Smtp服务器</summary>
    /// <value>
    /// 服务器是一个发送服务器. 确认它能中继信息</value>
    SmtpMail.SmtpServer=SMTPServerName.Text;
    /// <summary>
    /// Send发放用来把邮件发送到邮件列表</summary>
    /// <value>
    /// 法送邮件</value>
    try
    {
    SmtpMail.Send (myMail);
    }
    catch(Exception ex)
    {
    SMTPServerName.Text=ex.ToString();
    }
    /// 更新发送状态信息
    statusLabel.Text = "Mail has been sent";
    } ///<summary>
    /// 使用SmtpMail类法送邮件
    /// 只用设置他的一些属性就可以
    ///</summary>
    private void SendMessageNoMessageObj_Click(object sender, System.EventArgs e)
    {
    /// <summary>
    /// 设置发送者电子邮件</summary>
    /// <value>
    /// 邮件地址必须是可以可以被中继的mail服务器</value>
    string from = fromAddress.Text;
    /// <summary>
    /// 设置接收者电子邮件</summary>
    /// <value>
    /// 你想发送到的邮件地址.</value>
    string to = sendToAddress.Text;
    /// <summary>
    /// 设置电子邮件主题</summary>
    /// <value>
    /// 电子邮件主题</value>
    string subject = messageSubject.Text;
    /// <summary>
    /// 设置电子邮件内容</summary>
    /// <value>
    /// 可以设置内容格式,可以是Text或者Html</value>
    string body = messageBody.Text;
    /// <summary>
    /// 设置Smtp服务器</summary>
    /// <value>
    /// 服务器是一个发送服务器. 确认它能中继信息</value>
    SmtpMail.SmtpServer=SMTPServerName.Text;
    /// <summary>
    /// Send发放用来把邮件发送到邮件列表</summary>
    /// <value>
    /// 法送邮件</value>
    SmtpMail.Send(from, to, subject, body);
    /// 更新发送状态信息
    statusLabel.Text = "Mail has been sent";
    } /// <summary>
    /// 这个实例使用MailMessage演示怎么样发送附件
    /// </summary>
    private void SendMessageWithFile_Click(object sender, System.EventArgs e)
    {
    if (fileNameToAttach.Text == "" )
    {
    statusLabel.Text = "File name is required to send an attachment";
    return;
    }
    /// <summary>
    /// 创建一个MailMessage对象</summary>
    MailMessage mailWithAttachment = new MailMessage();
    /// <summary>
    /// 创建一个MailAttachment对象</summary>
    /// <value>
    /// 设置附件的内容</value>
    MailAttachment myAttachment = new MailAttachment(fileNameToAttach.Text);
    /// <summary>
    /// 把附件加到邮件对象的附件集合中</summary>
    /// <value>
    /// 添加操作</value>
    mailWithAttachment.Attachments.Add(myAttachment);
    /// <summary>
    /// 设置发送者电子邮件</summary>
    /// <value>
    /// 邮件地址必须是可以可以被中继的mail服务器</value>
    mailWithAttachment.From=fromAddress.Text;
    /// <summary>
    /// 设置接收者电子邮件</summary>
    /// <value>
    /// 你想发送到的邮件地址.</value>
    mailWithAttachment.To=sendToAddress.Text;
    /// <summary>
    /// 设置电子邮件内容</summary>
    /// <value>
    /// 可以设置内容格式,可以是Text或者Html</value>
    mailWithAttachment.Body=messageBody.Text;
    /// <summary>
    /// 设置电子邮件主题</summary>
    /// <value>
    /// 电子邮件主题</value>
    mailWithAttachment.Subject=messageSubject.Text;
    /// <summary>
    /// 设置Smtp服务器</summary>
    /// <value>
    /// 服务器是一个发送服务器. 确认它能中继信息</value>
    SmtpMail.SmtpServer=SMTPServerName.Text;
    /// <summary>
    /// Send发放用来把邮件发送到邮件列表</summary>
    /// <value>
    /// 法送邮件</value>
    SmtpMail.Send(mailWithAttachment);
    /// 更新发送状态信息
    statusLabel.Text = "Mail has been sent";
    }
    }
    }
    这样的原文件行没有?
      

  4.   

    http://search.csdn.net/Expert/topic/1347/1347604.xml?temp=.7648126
      

  5.   

    http://blog.csdn.net/goody9807/articles/30560.aspx
      

  6.   

    或许大家会很失望,为什么.NET的SMTP不支持ESMTP(身份认证),现在哪个SMTP不需要身份认证吖?真郁闷,微软老是喜欢做这种鸡肋。刚开始要用.NET的SMTP,那已经是2002年的事情了,发现它不支持ESMTP,就干脆改用了jmail,也就是要用InterOp,这种方法虽然的确是比不上纯.NET的,也是权宜之计。后来因为先是接收部分采用我参与开发的OpenPOP.NET,发现效果不错,就干脆全部采用纯.NET的,发送部分采用OpenSMTP.NET。最近发现了Reflector这个东西,其反编译效果不错,就是只能逐个函数解,实在是太不爽,后来hBifTs介绍了一个Reflector.FileDisassembler,效果好多了,可惜就是只能逐个Assembly解,它们都是很极端,一个解函数,一个解Assembly,就是不能解Class,看来我得自己写一个插件了。回到正题,既然有了工具,我就狠了一把,把.NET的整个System都反编译了,其中我最关心的是SMTP的实现,发现它竟然用了CDONTS这个历史遗物!!!连TCP都不用,就光会用那些鸡肋,实在让我失望!!!!同时,我还发现MIMEMapping类跟我在OpenPOP.NET中实现的方法一模一样,看来该开发人员也不咋地。而且其邮件编码只有BASE64和UUEncode,连非常常见的Quoted-Printable都没有。建议大家用OpenSMTP.NET,开源,功能强大,支持目前绝大部分SMTP特性,除了标准的正常发送和任意多附件,还支持如ESMTP(身份认证)、相关类型图片附件、特别好的中文支持等等。
      

  7.   

    http://bbs.mvpcn.net/ShowPost.asp?id=284
      

  8.   

    英文原版:http://www.ajiang.net/luntan/w3jmail4.pdf
      翻译后的:http://www.ajiang.net/luntan/w3jmail4_cn.pdf
      V3.7中文:http://www.ajiang.net/luntan/w3JMial37.pdf
      

  9.   

    在winform下用Outlook发邮件很容易
    Outlook.Application outObj=new Outlook.Application();
    Outlook.MailItemClass Item=new Outlook.MailItemClass();
    Item = outObj.CreateItem(0)        Item.To = "[email protected] "        Item.Subject = "hello"        Item.Body = "hell"        Item.Attachments.Add("C:\abc.txt")        Item.Send()