Questions about sending emails using Outlook

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.