There are two ways to send emails in ax, one is to use sysmailer class through CDO. the message component is sent, and the other is sent through the sysinetmail class using the ax-encapsulated mapi class. The latter is actually implemented by calling the outlook COM component, of course, emails that have been sent will be saved in the outlook on the client. This article mainly discusses the problems encountered when using the latter.
When using the batch mail sending function, a dialog box is displayed for you to click OK. The batch mail sending function is implemented through the Sendmail method of batchrun, which simplifiesCodeThe core code is as follows:
Static Void Sendmail (ARGs _ ARGs)
{
Sysinetmail mail = New Sysinetmail ();
;
Mail. Sendmail ( " Wanglai@126.com " , " Hello Outlook mail " , " Sendmail by Outlook Test " , False );
}
It can be seen that it is implemented through sysinetmail, Sendmail will call a series of methods, when the call to sysinetmailCycler=_ Mapi. resolvename (name, # mapi_dialog );
The following dialog box is displayed:
In this way, it is really painful to point this item every time. the cause is that ax's mapi class is considered insecure by outlook. in fact, ax already has a solution to this problem. You only need to use the mapiex class. I cannot figure out why Microsoft does not change the sysinetmail class to use mapiex, maybe it's cool for people all over the world to click this Allow button.
You can take a look at the sendemail method of smmoutlookemail. The code is simplified as follows: Static Void Extendedmapisendmail (ARGs _ ARGs)
{
Mapiex;
Mapiexmail;
Boolean mapiinitialised;
Com outlooknamespace;
Com outlook;
Com folder;
Com item;
STR entryid;
STR storeid;
Interoppermission permission;
# Define . Outlookapplication ("Outlook. application ")
# Define . Mapi ("mapi ")
# Smmmsoutlook2002objectmodelconstants;
Permission = New Interoppermission (interopkind: cominterop );
Permission. Assert ();
Outlook = New COM (# outlookapplication );
Outlooknamespace = Outlook. getnamespace (# mapi );
Outlooknamespace. Logon ();
Folder = Outlooknamespace. getdefaultfolder (# olfolderinbox );
Storeid = Folder. storeid ();
Item = Outlook. createitem (# olmailitem );
If (Item)
{
Item. Subject ( " Hello Outlook " );
Item. Body ( " Send mail by Outlook " );
Item. savesentmessagefolder (outlooknamespace. getdefaultfolder (# olfoldersentmail ));
Item. Save ();
Entryid = Item. entryid ();
Mapiex = New Mapiex ();
If (Mapiex && Mapiex. mapiinitialised ())
{
Mapiinitialised = True ;
If ( ! Mapiex. Logon ( "" , "" , 0 ) | ! Mapiex. openmessagestore (storeid ))
{< br> mapiinitialised = false ;< br> mapiex. logout ();
mapiex. finalize ();
return ;
}
Mapiexmail = Mapiex. getmailfromentryid (entryid );
If (Mapiexmail)
{
Mapiexmail. addrecipient ('Wanglai@126.com',"", # Olto );
}
Mapiexmail. Send ();
Mapiexmail. Close ();
}
}
If (Mapiinitialised)
{
Mapiex. logout ();
Mapiex. Finalize ();
}
}
In this way, the box will not pop up.