Line break in email message

2

In my string mensagem , I would like to have a space of two lines, I already tried to use "/ n" and did not get the expected result.

@{
    var customerName = Request["customerName"];
    var customerEmail = Request["customerEmail"];
    var customerRequest = Request["customerRequest"];
    var customerSubject = Request["customerSubject"];
    var atendimento = "[email protected]";
    var errorMessage = string.Empty;
    var debuggingFlag = false;
    string mensagem = string.Format(customerRequest + "\n\n{0}", customerEmail);
    try
    {
        // Initialize WebMail helper
        WebMail.SmtpServer = "smtp.teste.com.br";
        WebMail.SmtpPort = 25;
        WebMail.UserName = "[email protected]";
        WebMail.Password = "teste";
        WebMail.From = "[email protected]";

        // Send email
            WebMail.Send(to: atendimento,
                subject: customerSubject + " - " + customerName,
                body: mensagem
            );
    }
    catch (Exception ex)
    {
        errorMessage = ex.Message;
    }
}
    
asked by anonymous 13.11.2014 / 13:23

3 answers

3

Use Environment.NewLine instead of \n . It's the right one. I am considering that you are using the default to MailMessage .IsBodyHtml . Otherwise the solution passes by putting a <br/> .

Do not capture Exception . See more about this by following all the answers I've already started by this answer .

    
13.11.2014 / 13:30
1

In C # use Environment.NewLine more or less like this:

String mensagem = String.format(customerRequest + Environment.NewLine + Environment.NewLine + "{0}", customerEmail);
    
13.11.2014 / 13:30
1

Use "Environment.NewLine" concatenated with the rest of the message!

    
01.04.2017 / 02:11