0

この関数を介してテキスト/Html メールを送信しています。BodyMessage と mailSubject は Html テキストです。

しかし、メールを受信すると、「どうすれば削除できますか?」などの記号が含まれています。

    public static bool SendMailByTemplates(string toAddress, string ccAddress, string bccAddress, string mailSubject, string bodyMessage, List<KeyValuePair<string, String>> attachmentFile)
    {
        MailMessage msg = new MailMessage();
        GetConfigurationForAdmin();
        GetConfiguration();
        SmtpClient mailClient = new SmtpClient();
        if (toAddress == "Admin")
        {
            toAddress = toAdmin;
        }
        else if (ccAddress == "Admin")
        {
            ccAddress = toAdmin;

        }
        msg.From = new MailAddress(fromAddress);
        msg.To.Add(new MailAddress(toAddress));
        if (ccAddress != "" && ccAddress != null)
            msg.CC.Add(new MailAddress(ccAddress));
        if (bccAddress != "" && bccAddress != null)
            msg.Bcc.Add(new MailAddress(bccAddress));



            LinkedResource headerlogo = new LinkedResource(HttpContext.Current.Server.MapPath("~/Content/Images/EmailTemplateImages/logo.jpg"));

            headerlogo.ContentId = "headerlogo";


            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(bodyMessage, null, MediaTypeNames.Text.Html);
            htmlView.LinkedResources.Add(headerlogo);
            htmlView.LinkedResources.Add(greenlogo);
            htmlView.LinkedResources.Add(skylinelogo);

            msg.Subject = mailSubject;
           /* msg.Body = bodyMessage;
            msg.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");
            */
            if (attachmentFile != null)
            {
                foreach (KeyValuePair<string, String> attachment in attachmentFile)
                {
                    if (!(attachment.Key == null || attachment.Key == ""))
                    {

                        Attachment attach = new Attachment(attachment.Key);
                        attach.Name = attachment.Value;

                        msg.Attachments.Add(attach);

                    }
                }
            }


            msg.IsBodyHtml = true;
            NetworkCredential basicAuthenticationInfo = new NetworkCredential(fromAddress, password);
            mailClient.Host = host;
            mailClient.Port = port;
            mailClient.EnableSsl = true;
            mailClient.UseDefaultCredentials = false;
            mailClient.Credentials = basicAuthenticationInfo;
            System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(System.Text.RegularExpressions.Regex.Replace(bodyMessage, @"<(.|\n)*?>", string.Empty), null, "text/plain");
            msg.AlternateViews.Add(plainView);
            msg.AlternateViews.Add(htmlView);
            msg.ReplyTo = new MailAddress(replyAddress);

            mailClient.Send(msg);

        }

    }

上記の問題の解決策を教えてください。

4

1 に答える 1

0

htmlView の別のコンストラクターで確認します。

ContentType mimeType = new System.Net.Mime.ContentType("text/html");
var htmlView = AlternateView.CreateAlternateViewFromString(bodyMessage, mimeType);
于 2013-07-08T13:39:01.500 に答える