Other recent Dynamics AX Blog postings

Donnerstag, Dezember 21, 2006

Sending Emails via SMTP on AOS server

I had the following problem: our partner made a class which sends emails to users via SMTP using the SysMailer class. It works well using a local client. Unfortunately, when you run the class in batch, it gives you a .NET permission error (the BatchRun class has the RunOn property set to "server").

I don't have any knowledge in .NET, but fortunately I found a similar problem in Fred Shen's blog (http://fredshen.spaces.live.com/). I mailed him my problem and instantly got an anser and a solution !

Here is the Fred's answer. I tried it and it works! (I marked the changes to be done in the method with red color)

Whenever you initialize the sysmailer class, put InteropPermission.assert() before new SysMailer(). When you look into SysMailer.new() method, you may find that the COM c = new COM(' CDO .Message') is not in the scope of interopPermission.assert(). (I thought it should be a code defect) So alternatively, you can restructure the codes in SysMailer.New() as below:

void new(/* COM c = new COM(' CDO .Message')*/)
COM cdoConfig;
COM c;
InteropPermission permission = new InteropPermission(InteropKind::ComInterop);

c = new COM('CDO .Message');
_COM = c;
//BP Deviation Documented
if (_COM.configuration() == null)

And that's just what I want to achieve with my blog: to get to know people and to help each other. So again: THANX A LOT, FRED !

3 Kommentare:

Praveen Parameswaran hat gesagt…

I checked the Sysmailer class, it is using Dundas.mailer DLL not the CDO.Message object, Are talking about the AX 4.0. I currently saw the classes in the AX 3.0 SP3...

Praveen Parameswaran hat gesagt…
Dieser Kommentar wurde vom Autor entfernt.
Praveen Parameswaran hat gesagt…

I am not able to find anywhere the CDO code which can actually send the mail, i tried to execute the following code but no errors came but the mail was not sent to the To address.

server static void HCL_CDO(Args _args)

// Declare the Com Object Variable.
COM CDOMessage = null;
COM CDOConf = null;

// Instantiate the Com object CDOSYS.DLL (IMessage Interface)
CDOMessage = new COM("cdo.message");

// Set the To Line
// CDOMessage.To('ToAddr@xxxxxx.com');
// Set From Line
// Regular Text Body Format (Non-HTML Body)
CDOMEssage.TextBody('Body of Message');
// Message Subject
CDOMessage.Subject('Test Alert Mail');

// Send Message
CDOMessage = null;

Can you please tell me where we can find the CDO code to send the mail in Axapta...