【问题标题】:send mail in asp.net Bcc and CC在 asp.net Bcc 和 CC 中发送邮件
【发布时间】:2013-10-11 19:33:35
【问题描述】:

我使用代码发送邮件

public void sendmail()
{
    try
    {
        System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");  
        EmailServerDAL emailDAL = new EmailServerDAL();
        EmailServer emailServer = emailDAL.FindByCondition(c => true).FirstOrDefault();
        string mail = emailServer.Email;
        string mailserver = emailServer.Mailserver;
        int port = int.Parse(emailServer.Mailport.ToString());
        string pass = emailServer.Pass;
        string detail = CKEditorControl1.Text;
        if (mailserver == "smtp.gmail.com")
        {
            MailMessage em = new MailMessage();
            em.IsBodyHtml = true;//khai báo body là html
            em.BodyEncoding = System.Text.Encoding.UTF8;//khai báo body dùng mã UTF8
            //em.From = new MailAddress(CKEditorControl1.Text, "itool.vn");
            em.To.Add(new MailAddress(txtTo.Text, txtTitle.Text));
            //em.To.Add(new MailAddress(txtTo.Text, "ITOOL.VN"));
            if (!String.IsNullOrEmpty(TxtCC.Text))
            {
                em.CC.Add = TxtCC.Text.Replace(',', ';').Replace(" ", "");
            }
            if (!String.IsNullOrEmpty(txtBCC.Text))
            {
                em.Bcc.Add = (new MailAddress(txtBCC.Text.Replace(',', ';').Replace(" ", "")));
            }
            if (FileUpload1.HasFile)
            {
                string upload = Server.MapPath("~/upload/email/" + FileUpload1.FileName);
                FileUpload1.SaveAs(upload);
                Attachment attach = new Attachment(upload);
                em.Attachments.Add(attach);
            }
            em.Subject = txtTitle.Text;
            em.Body = detail;
            //em.IsBodyHtml = true;
            SmtpClient sm = new SmtpClient();
            sm.Host = "smtp.gmail.com";
            sm.EnableSsl = true;
            sm.Credentials = new NetworkCredential(mail, pass);
            sm.Send(em);
            lterror.Text = "<div class='Notice-Info'>Gởi mail thành công!</div>";
        }

}

我想发送邮件宽度密件抄送和抄送,但错误“无法分配给‘添加’,因为它是‘方法组’”

【问题讨论】:

    标签: asp.net email send


    【解决方案1】:

    MailMessage 上的Add 是一种方法,而不是属性。因此,您无需将 CC/BCC 列表分配给它,而是将其作为参数传递给任何其他函数。

    em.CC.Add(TxtCC.Text.Replace(',', ';').Replace(" ", ""));
    
    em.Bcc.Add(new MailAddress(txtBCC.Text.Replace(',', ';').Replace(" ", "")));
    

    【讨论】:

    • 如何添加密件抄送和抄送
    • @user2847541,正如我向您展示的那样。你到底有什么问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-05
    • 1970-01-01
    • 2018-01-22
    • 1970-01-01
    • 2017-01-25
    相关资源
    最近更新 更多