Write an ASP.net web site with a contact us form to send email to [email protected]. Use [email protected] as SENDER, get FROM from contact us form. Use local IIS SMPT as SMPT server. The following email header is expected:
Sender: <[email protected]>
Return-Path: <[email protected]>
Received: from iron2.hkstp.org [202.94.235.243] by MAIL.REASONABLES.COM with SMTP;
   Sun, 22 Mar 2009 04:16:05 -0400
Received: from smtp.hkstp.org ([192.168.106.16])
  by iron2.hkstp.org with ESMTP/TLS/DHE-RSA-AES256-SHA; 22 Mar 2009 16:16:12 +0800
Received: from ri (mail01.edm.hkstp.org [202.94.235.148])
by smtp.hkstp.org (8.13.4/8.13.4) with ESMTP id n2M8FW4L031832
for <[email protected]>; Sun, 22 Mar 2009 16:16:12 +0800
Date: Sun, 22 Mar 2009 16:16:12 +0800
From: John Smith<[email protected]>
Reply-To:<[email protected]>
To: <[email protected]>
Subject: Realizing Value from IT Investment写一ASP.net与我们联系表格发送电子邮件至[email protected]网站。使用[email protected]作为发件人,从我们接触到的形式。使用本地IIS SMPT作为SMPT服务器。下面的电子邮件标题预计:发件人:<[email protected]>返回路径:<[email protected]>收稿:从iron2.hkstp.org [202.94.235.243]通过MAIL.REASONABLES.COM与SMTP [202.94.235.243];   太阳,2009年3月22日4时16分05秒-0400收稿:从smtp.hkstp.org([192.168.106.16])  通过与ESMTP/TLS/DHE-RSA-AES256-SHA iron2.hkstp.org; 2009年3月22日16时16分12秒0800收稿:从里(mail01.edm.hkstp.org [202.94.235.148])由smtp.hkstp.org(8.13.4/8.13.4)与ESMTP编号n2M8FW4L031832为<[email protected]>;孙,2009年3月22日16点16分12秒0800日期:Sun,2009年3月22日十六点16分12秒0800来自:约翰史密斯<[email protected]>回复:<[email protected]>致:<[email protected]>主题:从IT投资实现价值

解决方案 »

  1.   

    pop收发邮件
    发送邮件可用MailMessage MyMail = new MailMessage();   
    System.Net.Mail.SmtpClient client
      

  2.   

    发送邮件代码:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using jmail;
    using System.Net.Mail;
    using System.Collections;namespace BusinessLayer
    {
        public class Send
        {        /// <summary>
            /// 通过jmail来发邮件
            /// </summary>
            /// <param name="server">邮件服务器</param>
            /// <param name="sender">发送方</param>
            /// <param name="password">邮箱密码</param>
            /// <param name="receiver">接受者</param>
            /// <param name="theme">主题</param>
            /// <param name="content">内容</param>
            /// <returns></returns>
            public static bool SendEmailByJmail(string server, string sender, string password, string receiver, string theme, string content)
            {
                try
                {
                    jmail.MessageClass jmessage = new jmail.MessageClass();
                    jmessage.Charset = "GB2312";
                    jmessage.From = sender;
                    jmessage.FromName = theme;
                    jmessage.Subject = theme;
                    jmessage.AddRecipient(receiver, "", "");
                    jmessage.Body = content;
                    jmessage.MailServerUserName = sender;
                    jmessage.MailServerPassWord = password;
                    jmessage.Send(server, false);                return true;
                }
                catch (Exception err)
                {
                    return false;
                }
            }        /// <summary>
            /// 通过.net提供的类来发邮件
            /// </summary>
            /// <param name="server">邮件服务器</param>
            /// <param name="sender">发送方</param>
            /// <param name="password">邮箱密码</param>
            /// <param name="receiver">接受者</param>
            /// <param name="theme">主题</param>
            /// <param name="content">内容</param>
            /// <returns></returns>
            public static bool SendEmailByNet(string server, string sender, string password, string receiver, string theme, string content)
            {
                try
                {
                    MailAddress from = new MailAddress(sender);
                    MailAddress to = new MailAddress(receiver);
                    MailMessage message = new MailMessage(from, to);
                    message.Subject = theme;
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    message.Body = content;
                    message.IsBodyHtml = true;
                    message.SubjectEncoding = System.Text.Encoding.Default;
                    message.BodyEncoding = System.Text.Encoding.Default;                SmtpClient client = new SmtpClient(server);
                    System.Net.NetworkCredential smtpuserinfo = new System.Net.NetworkCredential();
                    smtpuserinfo.UserName = sender;
                    smtpuserinfo.Password = password;
                    client.Credentials = smtpuserinfo;
                    client.Send(message);
                    return true;
                }
                catch (Exception err)
                {
                    return false;
                }
            }    }
    }
    需要下载一个jmail组件