首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • 请专家解析哈asp.net中邮件自动发送的问题 [已结贴,结贴人:duanlongk]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • duanlongk
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    • 揭帖率:
    发表于:2008-04-24 09:00:52 楼主
      请专家如果有空的话,能不能给一段源代码。谢谢了先
    20  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • iuhxq
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-04-24 09:27:511楼 得分:2
    利用asp.net+Jmail发送Email
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • kqh168
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-04-24 17:43:182楼 得分:1
    en 下个jmail组件,网上有很多相关资料,调用它提供的方法就可以
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • wapit
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-04-24 18:38:063楼 得分:1
    我也觉得用jmail稳定.
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • hecong875
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-04-24 18:48:284楼 得分:8
      protected void Button1_Click(object sender, EventArgs e)
        {
         

            //MailMessage mailobj = new MailMessage();
            //mailobj.From = "hecong";//发信人地址
            //mailobj.To = this.From.Text;//手见人地址
            //mailobj.Subject = this.Subject.Text;// 主题
            ////mailobj.Headers //标头
            //mailobj.Body = this.TextArea1.Value;// 正文
            //mailobj.Cc = "";
            //mailobj.Bcc = "";
            //mailobj.Priority = MailPriority.High;//有先级
            //mailobj.Attachments.Add(new MailAttachment());
            //SmtpMail.SmtpServer = "smtp.163.com";
            ////mailobj.Fields.Add(CdoConfiguration.cdoSMTPAuthenticate, "1");
            ////mailobj.Fields.Add(CdoConfiguration.cdoSMTPAuthenticate, "1");
            ////mailobj.Fields.Add(CdoConfiguration.cdoSendUserName, fSendUsername); //用户名
            ////mailobj.Fields.Add(CdoConfiguration.cdoSendPassword, fSendPassword); //密码 
            //mailobj.Fields.Add(CdoConfiguration.cdoSMTPAuthenticate, "1");
            //mailobj.Fields.Add(CdoConfiguration.cdoSendUserName, "XXXXX");
            //mailobj.Fields.Add(CdoConfiguration.cdoSendPassword, "XXXXX");
            //SmtpMail.Send(mailobj);
            //try
            //{
            //    SmtpMail.Send(mailobj);
            //}
            //catch (Exception ex)
            //{
            //    info.Text = ex.ToString(); 
            //}

        }
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • hecong875
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-04-24 18:51:505楼 得分:8
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Collections.Generic;
    using System.Drawing;
    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.Net.Mail;
    using OnMost.Utility.Entity;
    using OnMost.Utility.BusinessRule;

    public partial class E_Mail_Sys_Frm_SentMail : System.Web.UI.UserControl
    {
        static public ArrayList hif = new ArrayList();
        public int filesUploaded = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                MstEmpInfoEntity EmpInfoEntity = new MstEmpInfoEntity();
                SessionEntity session = (SessionEntity)Session["SysSessionData"];
                if (session.BusinessData as MstEmpInfoEntity != null)
                {
                    EmpInfoEntity = (MstEmpInfoEntity)session.BusinessData;
                    if (EmpInfoEntity.Mail != "")
                    {
                        this.txtmailto.Text = (EmpInfoEntity.Mail).Substring(0, (EmpInfoEntity.Mail).Length - 1);
                    }             
                }
            }
        }
        /// <summary>
        /// 初始化控件
        /// </summary>
        public void Pageload()
        {
            this.txtmailto.Text = string.Empty;
            this.txtmailtitle.Text = string.Empty;
            this.txtmailcontent.Value = string.Empty;
            this.lbFile.Items.Clear();
            hif.Clear();
        }
        /// <summary>
        /// 增加附件
        /// </summary>
        /// <param name="sender"> </param>
        /// <param name="e"> </param>
        protected void AddFile(object sender, EventArgs e)
        {
            if (Page.IsPostBack == true)
            {
                try
                {
                    hif.Add(FindFile);
                    lbFile.Items.Add(FindFile.PostedFile.FileName);
                }
                catch(System.Exception ex)
                {
                    lblErr.Text = ex.Message;
                }
            }


       
        }
        /// <summary>
        /// 附件删除
        /// </summary>
        /// <param name="sender"> </param>
        /// <param name="e"> </param>
        protected void RemvFile_Click(object sender, EventArgs e)
        {
            if (lbFile.SelectedIndex == -1)
            {
                lblErr.Text = "错误!请选择要删除的文件!";
            }
            else if(lbFile.Items.Count != 0)
            {
                hif.RemoveAt(lbFile.SelectedIndex);
                lbFile.Items.Remove(lbFile.SelectedItem.Text);
                lblErr.Text = "";
               
             
            }

        }

        /// <summary>
        /// 邮件发送
        /// </summary>
        /// <param name="sender"> </param>
        /// <param name="e"> </param>
        protected void SentMail(object sender, EventArgs e)
        {
            SmtpClient smtp = new SmtpClient();
            MailMessage mail = new MailMessage();
            string[] strFlie = null;
            string baseLocation = Server.MapPath("UploadFiles/"); // 服务器保存路径     
            string fn = null;//本地路径
            string Filfn = null;
            if (txtmailto.Text != string.Empty || txtmailto.Text !="")
            {
                if (txtmailtitle.Text != string.Empty || txtmailtitle.Text != "")
                {
                        EmpInfoBusinessRule EmpRule = new EmpInfoBusinessRule();
                        EmpRule.SessionData = (SessionEntity)Session["SysSessionData"];
                        EmpRule.GlobalData = (GlobalEntity)Application["SysGlobalData"];
                        IList <MstEmpInfoEntity> MailData = (List <MstEmpInfoEntity>)EmpRule.MailData();
                        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                        smtp.Host = "Mail.OnMost.com";
                        foreach (MstEmpInfoEntity info in MailData)
                        {
                            smtp.Credentials = new System.Net.NetworkCredential(info.Mail, info.MailPassword);
                            mail.From = new MailAddress(info.Mail);
                        }             
                        mail.To.Add(txtmailto.Text);
                        mail.Subject = txtmailtitle.Text;
                        mail.Body = txtmailcontent.Value;
                        mail.BodyEncoding = System.Text.Encoding.UTF8;
                        mail.IsBodyHtml = true;
                        mail.Priority = MailPriority.High;

                            if (hif.Count > 0)
                            {
                                foreach (System.Web.UI.HtmlControls.HtmlInputFile HIF in hif)
                                {

                           
                                        fn = System.IO.Path.GetFileName(HIF.PostedFile.FileName);
                                        HIF.PostedFile.SaveAs(baseLocation + fn);
                                        mail.Attachments.Add(new Attachment(baseLocation + fn));
                                        Filfn += baseLocation + fn+",";
                                       


                                }
                            }         
                     

                        try
                        {
                           

                            smtp.Send(mail);
                            this.Response.Write(" <script>alert('邮件发送成功!') </script>");
                            this.lblErr.Text = "";
                            mail.Attachments.Dispose();   
                          strFlie = (Filfn).Substring(0, (Filfn).Length - 1).Split(',');
                            for (int i = 0; i < strFlie.Length; i++)
                            {
                                if (strFlie[i] != null && strFlie[i] != "")
                                {
                                    System.IO.File.Delete(strFlie[i]);
                                }
                               
                            }
                               
                            Pageload();
                           
                           
                        }
                        catch (Exception ex)
                        {
                            mail.Attachments.Dispose();
                            strFlie = (Filfn).Substring(0, (Filfn).Length - 1).Split(',');
                            for (int i = 0; i < strFlie.Length; i++)
                            {
                                if (strFlie[i] != null && strFlie[i] != "")
                                {
                                    System.IO.File.Delete(strFlie[i]);
                                }

                            }
                            this.lblErr.Text = ex.Message;

                        }           
                }
                else
                {
                    this.lblErr.Text = "主题不能为空!";
                }
            }
            else
            {
                this.lblErr.Text = "收件人不能为空!";
            }
            mail.Attachments.Dispose();
            strFlie = (Filfn).Substring(0, (Filfn).Length - 1).Split(',');
            for (int i = 0; i < strFlie.Length; i++)
            {
                if (strFlie[i] != null && strFlie[i] != "")
                {
                    System.IO.File.Delete(strFlie[i]);
                }

            }
         
        }   
        protected void Quantity(object sender, EventArgs e)
        {
            this.Response.Redirect("/OnMostOA/E-Mail/Sys_Frm_SentMailPage.aspx");
        }


    }
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    北京创新乐知广告有限公司 版权所有 京 ICP 证 070598 号
    世纪乐知(北京)网络技术有限公司 提供技术支持
    Copyright © 2000-2008, CSDN.NET, All Rights Reserved