请给出一个简单的例子代码。另外问下,用email提交机器上必须使用outlook吗?如果没有安装outlook有办法提交表单到指定信箱吗?

解决方案 »

  1.   

    这是我发邮件的例子.楼主可以直接用.不过要用户名称空间.
    /// <summary>
    /// 发送邮件
    /// </summary>
    /// <param name="To">收件人</param>
    /// <param name="From">发件人</param>
    /// <param name="Subject">主题</param>
    /// <param name="Body">内容</param>
    /// <param name="IsHtml">是否Html格式</param>
    /// <returns>返回是否发送成功</returns>
    private static bool SendMail(string To,string From,string Subject,string Body,bool IsHtml)
    {
    bool IsOk = false;
    string SmtpServer = Global.SmtpServer.ToString();
    string SmtpUserName = Global.SmtpUserName.ToString();
    string SmtpPassWord = Global.SmtpPassWord.ToString();
    MailMessage Mail = new MailMessage();
    Mail.To = To;
    Mail.From = From;
    Mail.Subject = Subject;
    Mail.Body = Body;
    Mail.BodyFormat = (IsHtml) ? MailFormat.Html:MailFormat.Text;
    Mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
    if (SmtpUserName != "" && SmtpPassWord != "")
    {
    Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1");
    Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",SmtpUserName);
    Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",SmtpPassWord);
    }
    SmtpMail.SmtpServer = "192.168.1.2";//SmtpServer;
    try
    {
    SmtpMail.Send(Mail);
    IsOk = true;
    }
    catch//(Exception e)
    {
    //记录e.Message到日志
    }
    return IsOk;
    }
      

  2.   

    请试一下这个:www.goarena.net/mailonline.aspx
    如果发送成功,请向我索要源码!
      

  3.   

    "子风"一定合你意,不用outlook!采用web表单!
      

  4.   

    当时我做项目是写的,你参考一下吧!
    //**************************************************************发送邮件开始
    MailMessage myMail=new MailMessage();
    StringBuilder MailBody=new StringBuilder();
    myMail.From="[email protected]";
    myMail.To=email;
    myMail.Subject="主题xxxxxx";
    myMail.BodyFormat=MailFormat.Html; MailBody.Append("<style>A:visited { TEXT-DECORATION: none }");
    MailBody.Append("A:active  { TEXT-DECORATION: none }");
    MailBody.Append("A:hover   { TEXT-DECORATION: underline }");
    MailBody.Append("A:link    { text-decoration: none;}");
    MailBody.Append("A:visited { text-decoration: none;}");
    MailBody.Append("BODY   { FONT-FAMILY: Verdana,宋体; FONT-SIZE: 9pt;}");
    MailBody.Append("TD    { FONT-FAMILY: Verdana,宋体; FONT-SIZE: 9pt }</style>");
    MailBody.Append("<TABLE border=0 width='95%' align=center><TBODY><TR>");
    MailBody.Append("<TD valign=middle align=top>");
    MailBody.Append( DomainName + ",您好:<br><br>");
    MailBody.Append("欢迎您使用LINYI.NET免费域名系统,我们将提供给您最好的域名转向服务!<br><br>");
    MailBody.Append("下面是您的注册信息如下:<br>");
    MailBody.Append("域名:<b>"+DomainName+".linyi.net</b><br>");
    MailBody.Append("您的密码:"+pwd+"<br>");
    MailBody.Append("注册邮箱:"+email+"<br>");
    MailBody.Append("转向地址:"+url+"<br>");
    MailBody.Append("网站名称:"+siteName+"<br>");
    MailBody.Append("<br>现在您可以通过<a href='http://" +DomainName+ ".linyi.net' target='_blank'>http://" +DomainName+ ".linyi.net</a>或");
    MailBody.Append("<a href='http://www." +DomainName+ ".linyi.net' target='_blank'>http://www." +DomainName+ ".linyi.net</a>来访问您的网站,赶快试试吧!");
    MailBody.Append("<br><br>");
    MailBody.Append("<center><font color=red>全方位的.NET技术资源,尽在linyi.net!欢迎您下次光临!</font></TD></TR>");
    MailBody.Append( "<TR><TD align=right><a href='http://www.linyi.net' target='_blank'><img src='http://www.linyi.net/images/logo.gif' ");
    MailBody.Append( "border=0 alt='www.linyi.net'></a></TD></TR>");
    MailBody.Append("</TBODY></TABLE><br>"); myMail.Body=MailBody.ToString();

    myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
    myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "[email protected]");  //SMTP 用户
    myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "test");//'SMTP 密码
    SmtpMail.SmtpServer = "mail.xxx.com"; //SMTP服务器
    SmtpMail.Send(myMail);

    //************************************************************************发送邮件结束
      

  5.   

    private void btnSend_Click(object sender, System.EventArgs e)
    {
    //分别取得邮件的发信人、收信人、主题以及邮件主体等信息
    string strFrom = tbFrom.Text;
    string strTo = tbTo.Text;
    string strSubject = tbSubject.Text;
    string strMsgText = tbMsgText.Text;
    try
    {
    SmtpMail.SmtpServer = "smtp.sina.com.cn";
    SmtpMail.Send(strFrom,strTo,strSubject,strMsgText);
    //清除Label控件中的内容
    tbTo.Text = "";
    tbSubject.Text = "";
    tbMsgText.Text = "";
    lblShowMsg.Text = "发送至<b>"+strTo+"</b>邮件,发送成功";
    }
    catch(Exception ee)
    {
    lblShowMsg.Text = "发送邮件失败:"+ee.ToString();
    }
    }
    不用装outlook,只要邮件服务器可用就可以了。