I'm looking for a way to put linebreaks in the body of an EmailMessage()
in my UWP app.
I already tried with "\n"
, \r\n
, Environment.NewLine
, <br>
, <br />
, and every time it gets omitted whether on Desktop, on Mobile or both. I tried with Outlook and Gmail.
I'm using VS2015 update 3.
Thanks.
Edit: here's the code
public static async Task ComposeEmail(string address, string messageSubject, StorageFile attachmentFile)
{
var emailMessage = new EmailMessage();
emailMessage.Subject = messageSubject;
var lineBreak = Environment.NewLine;
string body = lineBreak + lineBreak + lineBreak + lineBreak + lineBreak + lineBreak + textLoader.GetString("EmailPleaseDontCut") + lineBreak + Info.GetAllInfos();
emailMessage.Body = body;
if (attachmentFile != null)
{
var stream = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(attachmentFile);
var attachment = new EmailAttachment(attachmentFile.Name, stream);
emailMessage.Attachments.Add(attachment);
}
emailMessage.To.Add(new EmailRecipient(address));
await EmailManager.ShowComposeNewEmailAsync(emailMessage);
}
I am showing an email like this and it's breaking it into two lines in the body
EmailMessage emailMessage = new EmailMessage()
{
Subject = "App Feedback " + Package.Current.DisplayName + " " + ApplicationServices.CurrentDevice,
Body = "First Line\r\nSecondLine"
};
emailMessage.To.Add(new EmailRecipient() { Address = "admin@DotNetRussell.com" });
await EmailManager.ShowComposeNewEmailAsync(emailMessage);
I think I read the same article you did on sending emails in UWP. That code you posted looks identical to it. That example sucked and it was wrong. The way I posted works way better.