简体   繁体   English

如何在我的html电子邮件中添加“分段符”?

[英]How can I add “paragraph breaks” to my html email?

I'm trying to add paragraph breaks in the email messages I generate. 我正在尝试在我生成的电子邮件中添加分段符。 I've tried both Environment.NewLine and adding multiple html paragraphs: 我已经尝试了Environment.NewLine并添加了多个html段落:

// Take 1, using Environment.NewLine:
htmlBody.Add(string.Format("<p>Hello {0}. You have been assigned the {1} on the " +
"<em>Apply Yourself to the Field Ministry</em> midweek meeting for the week beginning {2}.{3}{3}" +
"Your counsel point is {4}; if this is not a Bible reading, your HH is {5};{3}{3}" +
"You can find the material for your assignment in your Meeting Workbook.{3}{3}" + 
"Thank your for your paticipation!</p>",
    fullName, friendlyTalkType, weekOfTalk.ToLongDateString(), Environment.NewLine, counselPoint, HH, MWURL));

// Take 2, using p tags:
htmlBody.Add(string.Format("<div><p>Hello, {0}. You have been assigned the {1} on the " +
"<em>Apply Yourself to the Field Ministry</em> midweek meeting for the week beginning {2} (actual date is {3}).</p><p></p><p></p>" +
"<p>Your counsel point is {4}; if applicable, your HH is {5};</p><p></p><p></p>" +
"<p>You can find the material for your assignment in your Meeting Workbook or online here: {6}</p><p></p><p></p>" +
"Thank your for your participation!</p></div>",
    fullName, friendlyTalkType, weekOfTalk.ToLongDateString(),
    weekOfTalk.AddDays(DAYS_BETWEEN_MONDAY_AND_THURSDAY).ToLongDateString(),
    counselPoint, HH, MWURL));

In neither case is there vertical separation between the sections of text. 在两种情况下,文本部分之间都没有垂直分离。 What hoop do I need to vault myself through to accomplish this? 我需要什么箍来完成这个?

For context, here is the entire method: 对于上下文,这是整个方法:

public static void SendEmail(string fullName, string toEmail, string HH, int talkType, DateTime weekOfTalk, int counselPoint)
{
    const int DAYS_BETWEEN_MONDAY_AND_THURSDAY = 3;
    var fromAddress = new MailAddress(FROM_EMAIL, FROM_EMAIL_NAME);
    var toAddress = new MailAddress(toEmail, fullName);
    string fromPassword = GMAIL_PASSWORD;
    string subject = $"{UPCOMING_AYttFM_ASSIGNMENT} ({weekOfTalk.ToLongDateString()})";
    string friendlyTalkType = GetTalkTypeAsStringForInt(talkType);
    string body;
    string MWURL = GetLinkForMeetingWorkbookForWeek(weekOfTalk);

    List<String> htmlBody = new List<string>
        {
            "<html><body>"
        };
    htmlBody.Add(string.Format("<div><p>Hello, {0}. You have been assigned the {1} on the " +
     "<em>Apply Yourself to the Field Ministry</em> midweek meeting for the week beginning {2} (actual date is {3}).</p><p></p><p></p>" +
     "<p>Your counsel point is {4}; if applicable, your Householder is {5};</p><p></p><p></p>" +
     "<p>You can find the material for your assignment in your Meeting Workbook or online here: {6}</p><p></p><p></p>" +
     "Thank your for your participation!</p></div>",
        fullName, friendlyTalkType, weekOfTalk.ToLongDateString(),
        weekOfTalk.AddDays(DAYS_BETWEEN_MONDAY_AND_THURSDAY).ToLongDateString(),
        counselPoint, HH, MWURL));

    htmlBody.Add("</body></html>");
    body = string.Join("", htmlBody.ToArray());

    var smtp = new SmtpClient
    {
        Host = "smtp.gmail.com",
        Port = 587,
        EnableSsl = true,
        DeliveryMethod = SmtpDeliveryMethod.Network,
        UseDefaultCredentials = false,
        Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
    };
    using (var message = new MailMessage(fromAddress, toAddress)
    {
        Subject = subject,
        Body = body,
        IsBodyHtml = true
    })
    {
        smtp.Send(message);
    }
}

add </br> tag in paragraph. 在段落中添加</br>标签。 like this 像这样

htmlBody.Add(string.Format("<p>Hello </br>. You have been assigned the </br> on the " +
"<em>Apply Yourself to the Field Ministry</em> midweek meeting for the week beginning </br>" +
"Your counsel point is </br>; if this is not a Bible reading, your HH is </br>}" +
"You can find the material for your assignment in your Meeting Workbook.</br>" + 
"Thank your for your paticipation!</p>",

只需在Body-String中添加一个<br>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM