Reputation: 1909
We are facing a strange issue while sending email. It seems that the new line is not always working. Our code is
string mailSubject = "EBN Import Success. Client: " + ClientName.Trim();
StringBuilder mailBody = new StringBuilder("Client Name: " + ClientName.Trim());
mailBody.Append(System.Environment.NewLine + "File Name: " + FileName);
mailBody.Append(System.Environment.NewLine + "FileID: " + FileId);
mailBody.Append(System.Environment.NewLine + "BatchID: " + BatchID);
mailBody.Append(System.Environment.NewLine + System.Environment.NewLine + "Records in File (or staging): " + noOfRecords.ToString());
mailBody.Append(System.Environment.NewLine + "Records imported into BNCStaging: " + noOfRecords.ToString());
mailBody.Append(System.Environment.NewLine + "Records imported into EBNTrackings: " + noOfRecords.ToString());
string mailTo = ConfigurationManager.AppSettings["ErrorEmailTo"].ToString();
string mailFrom = ConfigurationManager.AppSettings["EmailFrom"].ToString();
string mailHost = ConfigurationManager.AppSettings["EmailServer"].ToString();
SmtpClient mailClient = new SmtpClient(mailHost);
mailClient.Send(mailFrom, mailTo, mailSubject, mailBody);
The output we are getting is
Client Name: [Client Name]File Name: [File Name]
FileID: nnnn
BatchID: mmmm
Records in File (or staging): x
Records imported into BNCStaging: y
Records imported into EBNTrackings: z
that is the client name and file name are coming in the same line.
We have also tried with AppendLine() and with '\n' without luck.
Any suggestions...
By the way we are using .net 4.0 and the mail client is outlook
Upvotes: 3
Views: 1251
Reputation: 21
It might sound ridiculous, but try adding a period to the Client Name line. As far as I have worked with this, this seems to force outlook into accepting the newline, instead of "intelligently" wrapping sentences together.
Upvotes: 2
Reputation: 33252
did you try to explicitly happend "\r\n"
at the end of the line ?
Upvotes: 0
Reputation: 887305
In Outlook, click Extra line breaks in this message were removed
, then click Restore line breaks
.
Upvotes: 3