MailItem formatting

Add-in Express™ Support Service
That's what is more important than anything else

MailItem formatting
MailItem formatting text 




Posts: 29
Joined: 2015-09-10
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
Posted 05 Feb, 2016 03:20:57 Top
Andrei Smolin


Add-in Express team


Posts: 18827
Joined: 2006-05-11
Hello Jerome,

In what event do you invoke that code?


Andrei Smolin
Add-in Express Team Leader
Posted 05 Feb, 2016 04:45:26 Top
jperciot




Posts: 29
Joined: 2015-09-10
Hi,

The event used is adxOutlookAppEvents_ItemSend

In this event, i get a reference object to the MailItem, and then i just prefix the body with some new text.
Posted 05 Feb, 2016 08:25:49 Top
Andrei Smolin


Add-in Express team


Posts: 18827
Joined: 2006-05-11
ItemSend supplies the item being sent. I don't understand why would you need to get the item selected and invoke Reply on it.


Andrei Smolin
Add-in Express Team Leader
Posted 05 Feb, 2016 09:01:11 Top
jperciot




Posts: 29
Joined: 2015-09-10
This event is used because, we open a dialog box on the mail selected in Outlook.
When this dialog box is validated, we prepare an object known to be a Quotation.

We call reply on this email.

Then we want to add the quotation object values inside of the body of the email.

and when the mail is sent, we save the transaction in our database.

Anyway, this does not answer my original question, which was how to use separators to write a text in the mail body like
"
DATA1
DATA2
DATA3"

Best regards
Posted 05 Feb, 2016 09:05:46 Top
Andrei Smolin


Add-in Express team


Posts: 18827
Joined: 2006-05-11
Will this work correctly if you call your code in the Click event of a test Ribbon button?

Mmm, in fact, I don't understand what goes wrong. Say, you posted an example of what you get. But what you expect to get? Is this question about formatting or about applying the formats in this specific scenario?


Andrei Smolin
Add-in Express Team Leader
Posted 05 Feb, 2016 09:38:54 Top