Hi,
I am developing a specific function when an item (email) is sent.
Here is my code :
Outlook.Selection selectedItem = _outlookApplication.ActiveExplorer().Selection;
if (selectedItem.Count != 0) {
Outlook.MailItem selectedMail = selectedItem[1] as Outlook.MailItem;
if (selectedMail != null) {
_message.Attachments.Add(selectedMail, Outlook.OlAttachmentType.olByValue, 1, selectedMail.Subject);
_message = selectedMail.Reply();
_message.Subject = string.Format("{0} [{1} : {2}]", _message.Subject, tag, _quotation.Code);
if (_quotationType == QuotationType.Light) {
// Change the Body Text
var _body = _message.Body;
String newBody = String.Empty;
// http://stackoverflow.com/questions/136052/how-do-i-format-a-string-in-an-email-so-outlook-will-print-the-line-breaks
String separator = String.Empty;
const String HTMLSeparator = "<br>";
const String PlainTextSeparator = "
";
switch (_message.BodyFormat) {
case Outlook.OlBodyFormat.olFormatHTML:
separator = HTMLSeparator;
break;
case Outlook.OlBodyFormat.olFormatPlain:
case Outlook.OlBodyFormat.olFormatRichText:
case Outlook.OlBodyFormat.olFormatUnspecified:
separator = PlainTextSeparator;
break;
default:
// This case should never happen, but it is better to endup with a default case label.
separator = PlainTextSeparator;
break;
};
newBody = String.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}",
InternationalizeMailRow(I18nMailRow.QuotationCode, Quotation.Code, separator),
InternationalizeMailRow(I18nMailRow.QuotationCustomer, Quotation.Customer.CustomerName, separator),
InternationalizeMailRow(I18nMailRow.QuotationReference, Quotation.Description, separator),
InternationalizeMailRow(I18nMailRow.QuotationDeparture, Quotation.Departure != null ? Quotation.Departure.Description : Quotation.DepartureDescription, separator),
InternationalizeMailRow(I18nMailRow.QuotationArrival, Quotation.Arrival != null ? Quotation.Arrival.Description : Quotation.ArrivalDescription, separator),
InternationalizeMailRow(I18nMailRow.QuotationParcels, new ParcelInfo(Quotation.NbParcels, Quotation.PackingType, Quotation.GoodsType), separator),
InternationalizeMailRow(I18nMailRow.QuotationCaracteristics, new GoodCaracteristics(Quotation.GrossWeight, Quotation.Volume, Quotation.FloorLength), separator),
InternationalizeMailRow(I18nMailRow.QuotationIncoterm, Quotation.Incoterm, separator),
InternationalizeMailRow(I18nMailRow.QuotationSaleAmount, Quotation.Amount, separator),
InternationalizeMailRow(I18nMailRow.QuotationValidity, Quotation.ValidityDate, separator)
);
_message.Body = String.Join(separator, newBody, _body);
The function InternationalizeMailRow takes values and format them using Datas / String.Format.
But in result, the email is NOT formatting as i need, here is a result :
Cotation : 500257Etablie pour le compte de : LOG SYSTEMConcernant : 0 (nb colis) (emballage) de : (nature marchandise)Caract?ristiques : 0 KG, 0 m3, 0 mValide jusqu'au : 06/03/2016
-----Message d'origine-----
De : forum@add-in-express.com [mailto:forum@add-in-express.com]
Envoy? : jeudi 4 f?vrier 2016 20:47
À : Jerome PERCIOT <j.perciot@logsystem.fr>
Can you figure it out and help me in formatting it correctly using the correct NewLine separator for both Email and PlainText ?
best regards |