您目前尚未登陆,请选择【登陆】或【注册
首页->功能源码->ASP.net邮件发送源码(51aspx原创)>>51aspxMail/Default.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:ASP.net邮件发送源码(51aspx原创)
当前文件:文件类型 JH1GEZ9ACZA70/51aspxMail/Default.aspx.cs打开代码结构图
高亮显示
		            using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Util;
using System.Web.Mail;

namespace _51aspxMail
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                format.Items.Add(new ListItem("文本", "0"));
                format.Items.Add(new ListItem("HTML", "1"));
                format.Items[0].Selected = true;

                fromMail.Text = "test@51aspx.com"; //发送方邮件
                fromMail.Enabled = false;
            }
        }

        private bool SendMail(string fromMail, string toMail, string ccMail, string bccMail, string subject, string body, string sendMode)
        {
            try
            {
                MailMessage myMail = new MailMessage();
                myMail.From = fromMail;
                myMail.To = fromMail;
                myMail.Cc = ccMail;
                myMail.Bcc = bccMail;
                myMail.Subject = subject;
                myMail.Body = body;
                myMail.BodyFormat = sendMode == "0" ? MailFormat.Text : MailFormat.Html;

                //附件
                string ServerFileName = "";
                if (this.upfile.PostedFile.ContentLength != 0)
                {
                    string upFileName = this.upfile.PostedFile.FileName;
                    string[] strTemp = upFileName.Split('.');
                    string upFileExp = strTemp[strTemp.Length - 1].ToString();
                    ServerFileName = Server.MapPath(DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp);
                    this.upfile.PostedFile.SaveAs(ServerFileName);
                    myMail.Attachments.Add(new MailAttachment(ServerFileName));
                }


                myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
                myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "ok2008"); //发送方邮件帐户
                myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "123456"); //发送方邮件密码

                SmtpMail.SmtpServer = "smtp." + fromMail.Substring(fromMail.IndexOf("@") + 1);
                SmtpMail.Send(myMail);

                return true;
            }
            catch
            {
                return false;
            }
        }

        protected void send_Click(object obj, EventArgs e)
        {
            bool flag = SendMail(fromMail.Text, toMail.Text, ccMail.Text, bccMail.Text, subject.Text, body.Text, format.SelectedValue);
            if (flag == true)
            {
                Response.Write("<script>alert('发送成功!');</script>");
            }
            else
            {
                Response.Write("<script>alert('发送失败!');</script>");
            }


        }
    }
}

        
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:ASP.net邮件发送源码(51aspx原创)
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号