I am modifying the Mail Codeunit to include a standard message when the interaction log is run. I am trying to format the Body of the email to be in HTML, but am having little success.
I checked the object browser for the standard outlook mailitem, as I believe the 'NS Outlook Synchronization Handler'.OSendMail is just a wrapper for that object. It appears that the BodyFormat property accepts 2 for HTML format, however I am not getting it in HTML. Here is a sample of what I am doing. Any ideas?
OSendMail."To" := ToName;
OSendMail.CC := CCName;
OSendMail.Subject := Subject;
Body:= 'This is a test of the <B>emergency</B> <U>broadcast</U> system...';
IF ISCLEAR(BSTRConverterBody) THEN
CREATE(BSTRConverterBody);
IF Body <> '' THEN BEGIN
BSTRConverterBody.ResetBSTR;
BSTRConverterBody.AppendNextStringPortion(Body);
END;
OSendMail.Body := BSTRConverterBody;
OSendMail.BodyFormat(2);
IF ISCLEAR(BSTRConverterAttachFileName) THEN
CREATE(BSTRConverterAttachFileName);
IF AttachFileName <> '' THEN BEGIN
BSTRConverterAttachFileName.ResetBSTR;
BSTRConverterAttachFileName.AppendNextStringPortion(AttachFileName);
OAttachments := OSendMail.Attachments;
OAttachment := OAttachments.Add(BSTRConverterAttachFileName);
END;
OSendMail.OpenDialog := OpenDialog;
MailSent := OSendMail.Send;
ErrorNo := OSendMail.ErrorStatus;
OApplication.Logoff;
0
Comments
Another reason could be the Outlook-client setup: What type of mail format are the outlook-client using (Tools -> Mail-format)?
Nada...
It is true - OutlookSyncHandler wraps Body Property of the MailItem. The BodyFormat property specifies the message format only and does not allow the use of HTML tags.
MailItem has a property called HTMLBody to enable using HTML, but OutlookSyncHandler currently does not wrap it.
Dmitry
Mike
If you are talking about E-Mail logging functionality that loggs outgoing e-mails as Interaction Log Entries, then you don't have to worry. When you send an e-mail (no matter how) you should have a rule in Outlook which places this e-mail into your Queue folder, then Navision checks this folder (interval and other settings are defined in the Relationship Management Setup) and retrieves this mail. After that Navision tries to find out if an interaction has been already logged for it using the LoggedAsInternalInteraction procedure in COD5064 and if it finds this ILE - it links the e-mail in outlook with this ILE.
So you can make your own code that sends e-mails using Outlook Object Model. Just remember that OSendMail supresses Outlook Security Messages while sending e-mails (those where you have to confirm that another application is sending the e-mail on your behalf). When programming against OOM you cant avoid them and it can be very annoing...
And I also dont think that you can intersept OSendMail - the Save method for it is not exposed either, no Save - no EntryID, no object to intersept...
Dmitry
I was able to send an E-Mail Signature generated by Navision to Outlook formatted as HTML.
If you are using Navision 3.7, I recommend you update your E-Mail code to match Navision 4.0 as much as possible.
I use Navision 3.7 on Windows XP and Outlook 2003.
To update the 3.7 code to match 4.0 code:
I updated my E-Mail code to act like Navision 4.0 because 4.0 uses the OLHandler.dll which eliminates the Outlook Security Popups we got when we sent mails through Navision, when Outlook tried to pop up a scheduled task, and when Navision tried to log E-Mails.
I registered the OLHandler.dll that 4.0 uses.
I upgraded the "Mail" codeunit to match the 4.0 Mail codeunit with all the same code and same variables.
I exported all the codeunits, reports, forms, and tables I could export as text files and searched through them to find any "Unknown Automation" objects. Where those objects called for Outlook, I assigned them the Automation object created by registering the OLHandler.dll. The automatian object name is called 'NS Outlook Synchronization Handler'.
(We still get the Outlook security pop-up when we first assign the Outlook folders on the Salesperson Card form that Navision will use to synchronize with, but that is only done once; and, we still get the pop ups when we use Interaction Templates that use MS Word to merge with Outlook. That doesn't happen very often, since only our advanced users utilize those Interaction Templates anyway. Otherwise, our Outlook Integration is free or warning pop ups).
To format the mail to HTML:
I modified the NewMessage function in the Mail codeunit by adding the "OSendMail.BodyFormat(2);" command line to tell the MailHandler to use HTML format.
I created a chrLineBreak variable of data type "Char."
I assigned this variable the value of 13 and when I used the AddBodyLine to write it to Outlook, I formatted the chrLineBreak variable to a string:
AddBodyLine(FORMAT(chrLineBreak));
Doing all the above. I had a Navision runnig 3.7 without Outlook security popups, using line breaks, and formatting in HTML.
Below is an example of the Outlook Signature coming out in HTML format:
IF ISCLEAR(OApplication) THEN
CREATE(OApplication);
IF (NOT OApplication.Logon(TRUE,'','',FALSE,FALSE)) THEN BEGIN
OApplication.Logoff;
EXIT
END;
IF ISCLEAR(OSendMail) THEN
CREATE(OSendMail);
ErrorNo := 0;
OSendMail."To" := ToName;
OSendMail.CC := CCName;
OSendMail.Subject := Subject;
IF ISCLEAR(BSTRConverterBody) THEN
CREATE(BSTRConverterBody);
chrLineBreak := 13; // Assign char(13) value to char variable
recCompanyInformation.RESET(); // "Company Information" Table
recCompanyInformation.INIT();
IF recCompanyInformation.FIND('-') THEN
BEGIN
txtCompanyName := recCompanyInformation."Name 2";
txtHomePage := recCompanyInformation."Home Page";
END;
recSalesperson.RESET(); // "Saleperson/Purchaser" Table
recSalesperson.INIT();
recSalesperson.SETRANGE("Navision User ID",USERID);
IF recSalesperson.FIND('-') THEN
BEGIN
AddBodyline(FORMAT(chrLineBreak)); // put in line break
AddBodyline(FORMAT(chrLineBreak)); // put in line break
AddBodyline(recSalesperson.Name);
AddBodyline(FORMAT(chrLineBreak)); // put in line break
AddBodyline(recSalesperson."Job Title");
AddBodyline(FORMAT(chrLineBreak)); // put in line break
AddBodyline(txtCompanyName);
AddBodyline(FORMAT(chrLineBreak)); // put in line break
AddBodyline(recSalesperson."Phone No.");
AddBodyline(FORMAT(chrLineBreak)); // put in line break
AddBodyline(recSalesperson.FaxNo);
AddBodyline(FORMAT(chrLineBreak)); // put in line break
AddBodyline(txtHomePage);
END;
IF Body <> '' THEN BEGIN
BSTRConverterBody.ResetBSTR;
BSTRConverterBody.AppendNextStringPortion(Body);
END;
OSendMail.Body := BSTRConverterBody;
OSendMail.BodyFormat(2);
IF ISCLEAR(BSTRConverterAttachFileName) THEN
CREATE(BSTRConverterAttachFileName);
IF AttachFileName <> '' THEN BEGIN
BSTRConverterAttachFileName.ResetBSTR;
BSTRConverterAttachFileName.AppendNextStringPortion(AttachFileName);
OAttachments := OSendMail.Attachments;
OAttachment := OAttachments.Add(BSTRConverterAttachFileName);
END;
OSendMail.OpenDialog := OpenDialog;
MailSent := OSendMail.Send;
ErrorNo := OSendMail.ErrorStatus;
OApplication.Logoff;
I hope this helps.
relliot
Hmm, how does your AddBodyline function look like? I remember having a problem with sending emails > 1024 chars
AddBodyLine('First part of broken str');
AddBodyLine('ing and middle part of broken str');
AddBodyLine('ing and last part of brokent string.');
When it's sent to Outlook, it would look like "First part of broken string and middle part of broken string and last part of broken string."
If you needed to, I guess you could create entire paragraphs that way, and I would use this to send autogenerated E-Mails.
However, for regular E-Mails sent to customers and so forth, we have the CRM module for Navision and it's integrated with Outlook. Se we just use Navision to Open Outlook and add the E-Mail Signature to the body and initialize the HTML format. Then the rest is done within Outlook itself.
I have worked with the SMTP ocx that you can download also from mibuso.com to send auto generated E-Mails, and after looking at the new Outlook Automation object that is created by the OLHandler.dll, I beleive the OLHandler.dll has the same functionality (once you update your 3.7 code to match 4.0 to eliminate outlook warning pop ups). Both can add lines up to 1024 characters, and it looks like both support Bcc addresses. (That is, I see that the Bcc is available in the OLHandler.dll, but I haven't tried it yet.)
But in my experience with the SMTP ocx, it does not put a copy of the E-Mail in a user's sent items, and when you add a line, it adds a line, and when you add another line, it creates a brand new line and doesn't let you insert them back to back so if you typed:
ocxSMTP.AddLine('First part of broken str');
ocxSMTP.AddLine('ing and middle part of broken str');
ocxSMTPAddLine('ing and last part of brokent string.');
It would look like:
First part of broken str
ing and middle part of broken str
ing and last part of broken str
Personally, I like the new OLHandler.dll.
I hope that this is helpful, and I hope that it is not too much writing for a simple answer.
relliot
It did change the body type to HTML
but all my begin and end tag are converted to > and < notation.
so ....
it didn't work.
Does anybody have an idea how i can skip the text buffer sh$t from navision?
Regards,
...
Everybody on-line.
...
Looking good!
olFormatUnspecified 0 Format non spécifié. texte brut.
olFormatPlain 1 Le texte de Body est en texte brut.
olFormatHTML 2 Le texte de Body est en HTML.
olFormatRichText 3 le texte de Body est en RTF.
lui préférer le HTML pour des raisons de compatibilité de lecteurs de messagerie.
You have to put it in the Codeunit 397 'Mail', like:
NewMessage(ToName : Text[80];CCName : Text[80];Subject : Text[260];Body : Text[260];AttachFileName : Text[260];OpenDialog : Boolean) Ma
IF ISCLEAR(OApplication) THEN
CREATE(OApplication);
IF (NOT OApplication.Logon(TRUE,'','',FALSE,FALSE)) THEN BEGIN
OApplication.Logoff;
EXIT
END;
IF ISCLEAR(OSendMail) THEN
CREATE(OSendMail);
ErrorNo := 0;
OSendMail."To" := ToName;
OSendMail.CC := CCName;
OSendMail.Subject := Subject;
//>>CHRE
OSendMail.BodyFormat := 2;
//<<CHRE
IF ISCLEAR(BSTRConverterBody) THEN
CREATE(BSTRConverterBody);
...
I work with Codeunit 397 (NAV 2009 SP1). In Function NewMessage the format is set zu html: OSendMail.BodyFormat(2);
Lines are set with AddBodyline. If in the lines there are html-tags they are not interpreted. E.g. <b> is in the mail instead of a bold text.
What could I do to change this?
My second trial is to work directly with the outlook library. The mailitem.htmlbody is limited to 1024 - my mailtexts are longer than this so I'm as far as before. Is there a way to add more text than 1024 signs via outlook-automations?
Does anybody know a solution for one of the problems?
Greetings,
Sandra
We can send SMTP emails with HTML formatting but we would like to be able send HTML emails via Outlook so that it shows up in a users Sent Items folder.
Is there anyway to add an HTML document as the body of an Outlook email?
Thanks in advance...
It should be possible with Word2010 automation controls as well. Create a word doc and send it through Word.
Inspired by other postings about the AddObject of the scriptcontrol
http://www.mibuso.com/forum/search.php?keywords=AddObject&terms=all&author=&sc=1&sf=all&sk=t&sd=d&sr=topics&st=0&ch=300&t=0&submit=Search+the+forum
That is a brilliant piece of code.
Code:
Name DataType Subtype Length
HTMLText_l Text 250
olApplication Automation 'Microsoft Outlook 15.0 Object Library'.Application
olMailItem Automation 'Microsoft Outlook 15.0 Object Library'.MailItem
Code:
IF ISCLEAR(olApplication) THEN
IF NOT CREATE(olApplication) THEN
ERROR('Outlook nicht gefunden!');
olMailItem := olApplication.CreateItem(0);
HTMLText_l := STRSUBSTNO('<a href="%1">Link</a>', CurrForm.URL);
olMailItem."To" := 'HansimGlück@Wunderland.de';
olMailItem.CC := 'HansimGlück@Wunderland.de';
olMailItem.Subject := 'Test';
olMailItem.HTMLBody := HTMLText_l;
olMailItem.Display;
Robert's Dynamics NAV Blog - Vom NAV Entwickler für NAV (Navision) Interessierte
Nope, in my example you don't have to do this. This additional security warning of outlook will be raised, if you use unsecure code! I.E. send an email directly. Show an email isn't unsecure code and thats why, you got no security warning.
Robert's Dynamics NAV Blog - Vom NAV Entwickler für NAV (Navision) Interessierte
so the example from BernardJ will trigger it because of ".Send".
Any other limitations? what happens if you want to send 20 invoices thru email? It will open 20 windows and you only have to click on "Send". Correct?