-1

我试图给出这样的电子邮件外观:

   This is the looks of my email

在此处输入图像描述 电子邮件主题的右侧是 Ignou 徽标,它是 jpg 图像。我有以下发送电子邮件的类,它工作正常:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Configuration;
    using System.Net.Configuration;
    using System.Net.Mail;

    namespace ProductManagementweb.HelperClasses
    {
      public class SendEmail
    {
    public static int SendMail(string ReceiverAddress, string Recsubject, string Recbody)
    {
        try
        {
            System.Configuration.Configuration config =                        WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
            MailSettingsSectionGroup settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");

            System.Net.NetworkCredential credential = new System.Net.NetworkCredential(settings.Smtp.Network.UserName, settings.Smtp.Network.Password);

            //Create the SMTP Client
            SmtpClient client = new SmtpClient();
            client.Host = settings.Smtp.Network.Host;
            client.Credentials = credential;
            client.Timeout = 30000;
            client.EnableSsl = true;

            MailMessage mm = new MailMessage();
            mm.From = new MailAddress(settings.Smtp.Network.UserName, "Support Team (Clique City)");
            mm.To.Add(ReceiverAddress);
            mm.Priority = MailPriority.High;


            // Assign the MailMessage's properties
            mm.Subject = Recsubject;
            mm.Body = Recbody;
            mm.IsBodyHtml = false;


            client.Send(mm);
            return 1;
        }

        catch (Exception ex)
        {
            throw ex;

        }
    }
  }
}

我怎样才能像上面的图片一样提供电子邮件格式,我确信我必须使用 html 标签来提及格式,但我不知道我必须在哪里提及以及如何提及。因此,任何帮助都将不胜感激。

4

2 回答 2

1

您应该将电子邮件设计中的 html 内容放在 Recbody 中,即电子邮件正文并更改

mm.IsBodyHtml = false;

mm.IsBodyHtml = true;
于 2013-10-09T09:11:07.487 回答
0

除了 vivekd 的回答。

您只需要在代码中构建 HTML,例如

string messageContent = "";
messageContent += "<table><tr><td>" + telephoneNumber + "</td><td>" + locationAddress + "</td></tr></table>"

然后设置

mm.IsBodyHtml = true;

并发送电子邮件内容为messageContent

mm.Body = messageContent;

显然,您需要自己设计电子邮件的布局并通过附加到messageContent字符串来构建它。

于 2013-10-09T09:29:31.660 回答