注册 登录
编程论坛 ASP.NET技术论坛

不允许使用邮箱名称

juk 发布于 2008-06-22 20:42, 946 次点击
不允许使用邮箱名称。 服务器响应为: authentication is required,smtp1,C9GowLCLh_BOSF5IYYiYCQ==.54420S2 1214138447

using System;
using System.Data;
using System.Configuration;
using System.Web;
using
using System.Web.Security;
using
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        //设置MailMessage类的to属性所需的MailAddress
        MailAddress toAddress = new MailAddress(this.tbReceiver.Text.Trim());
        //设置MailMessage类的from属性所需的MailAddress
        MailAddress fromAddress = new MailAddress(this.tbSender.Text.Trim());
        //新建一个MailMessage类实例
        MailMessage message = new MailMessage(fromAddress, toAddress);
        //设置这个实例的Subject属性
        message.Subject = this.tbSubject.Text;
        //设置这个实例的Body属性
        message.Body = this.tbMessage.Text;
        //添加附件
        //获得文件
        HttpPostedFile postedFile = file.PostedFile;
        //当有附件时
        if (postedFile.ContentLength != 0)
        {
            //声明一个Attachment类实例
            Attachment data = new Attachment(postedFile.FileName);
            message.Attachments.Add(data);
        }
        //设置正文格式
        if (rblFormat.SelectedItem.Text == "纯文本格式")
            message.IsBodyHtml = false;
        else
            message.IsBodyHtml = true;
        //添加抄送地址
        if (this.tbCc.Text != "")
        {
            MailAddress ccAddress = new MailAddress(this.tbCc.Text);
            message.CC.Add(ccAddress);
        }
        //添加暗送地址
        if (this.tbBcc.Text != "")
        {
            MailAddress bccAddress = new MailAddress(this.tbBcc.Text);
            message.Bcc.Add(bccAddress);
        }
        //新建一个SmtpClient类的实例
        SmtpClient client = new SmtpClient();
        //设置在本机smtp服务器中绑定的ip地址,本例为本机ip地址
        client.Host = "SMTP.
        //smtp端口,默认为25
        client.Port = 25;
        //发送
        client.Send(message);
        //发送完毕后提示
        Response.Write("<script language='javascript'>alert('发送成功')</script>");
    }
}
0 回复
1