oSendMail Object

mstallmann
Member Posts: 138
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;
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
-
Is it possible that you're not getting any HTML-formatting due to the fact that your body-code are without the HTML-tags (<html> </html>)?
Another reason could be the Outlook-client setup: What type of mail format are the outlook-client using (Tools -> Mail-format)?0 -
-
Hi,
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.Best regards,
Dmitry0 -
MS said they didn't expose that property in the wrapper. Did you find a way around that? I know I could use the Native Outlook object, but I beleive I would loose the interaction log entry functionality...i.e. linking the email in the record, etc. I also thought maybye after the item was created using the Navision object, I could somehow find and intercept it using the Outlook objects.
Mike0 -
but I beleive I would loose the interaction log entry functionality...i.e. linking the email in the record...
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...Best regards,
Dmitry0 -
I may have the solution, depending on what you are trying to do.
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.Best Regards,
relliot0 -
relliot wrote:I may have the solution, depending on what you are trying to do.
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.
Hmm, how does your AddBodyline function look like? I remember having a problem with sending emails > 1024 charsNavision developer0 -
Since the AddBodyLine() function only inserts text within the parentheses and does not put in any line breaks, you could insert two or more strings of 1024 characters back to back and they would look like one. For instance, if you wrote:
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.Best Regards,
relliot0 -
i've tried the bodyformat thingy.
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,Now, let's see what we can see.
...
Everybody on-line.
...
Looking good!0 -
The Value of the property for the body of an eMail is:
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);
...0 -
Hi there,
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,
Sandra0 -
Has anyone got a workable solution to this problem? I have the same issues as skaufmann.
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?0 -
I am wondering if anyone has found an issue to this problem. We can send html emails using SMTP, but not with Outlook object. Would like to use the wrapped object for future upgrades as well as the security message. If you have a direct method that takes these issues into account, I would be very interested as well.
Thanks in advance...0 -
Have a look at this: http://www.mibuso.com/dlinfo.asp?FileID=1412
It should be possible with Word2010 automation controls as well. Create a word doc and send it through Word.0 -
it is possible to overcome the Nav text buffer limit by executing the statement in concern in VB script
OBJECT Codeunit 50000 htmlbody { OBJECT-PROPERTIES { Date=01-06-12; Time=21:14:14; Modified=Yes; Version List=; } PROPERTIES { OnRun=BEGIN END; } CODE { PROCEDURE CreateOutlookMail@1000000004(); VAR lAutOutlook@1000000002 : Automation "{00062FFF-0000-0000-C000-000000000046} 9.4:{0006F03A-0000-0000-C000-000000000046}:'Microsoft Outlook 14.0 Object Library'.Application"; lAutMailItem@1000000001 : Automation "{00062FFF-0000-0000-C000-000000000046} 9.4:{00061033-0000-0000-C000-000000000046}:'Microsoft Outlook 14.0 Object Library'.MailItem"; VBScript@1000000030 : OCX "{0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC}:'ScriptControl Object'"; lAutStreamADO@1000000029 : Automation "{B691E011-1797-432E-907A-4D8C69339129} 6.0:{00000566-0000-0010-8000-00AA006D2EA4}:'Microsoft ActiveX Data Objects 6.0 Library'.Stream"; adTypeText@1000000031 : Integer; BEGIN CREATE(lAutOutlook); lAutMailItem := lAutOutlook.CreateItem(0); lAutMailItem.Recipients.Add('somebody@somewhere'); lAutMailItem.Subject('subject'); adTypeText := 2; CREATE(lAutStreamADO); lAutStreamADO.Open; lAutStreamADO.Type := adTypeText; REPEAT lAutStreamADO.WriteText('html messagepart'); UNTIL message is complete lAutStreamADO.Position(0); VBScript.Language('VBScript'); VBScript.AddObject('Mailitem',lAutMailItem); VBScript.AddObject('ADOstream',lAutStreamADO); VBScript.ExecuteStatement('Mailitem.HTMLBody = ADOstream.ReadText'); lAutStreamADO.Close; lAutMailItem.Send; END; BEGIN END. } }
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+forum1 -
Thank you BernardJ
That is a brilliant piece of code.0 -
This works, too:
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;0 -
I think both examples will trigger the "security question" from outlook, So you must click an extra Yes in a messagebox.0
-
mdPartnerNL wrote: »I think both examples will trigger the "security question" from outlook, So you must click an extra Yes in a messagebox.
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.0 -
ok, so you are not using outlook contact fields, and only using the Display command, that's why no security message.
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?0 -
We have found a way where we don't have these security questions, perhaps we can assist you with the issues of your customershttp://www.vssolutions NAV-Outlook synchronisation re-invented.0
-
well, in the above examples the mailitem.send() triggers the security warning. Any other way?0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions