Thursday 28 December 2017

send mail withy pdf in ax 2012

SysEmailParameters parameters = SysEmailParameters::find();
    FilePath FilePath;
    SMTPRelayServerName relayServer;
    SMTPPortNumber portNumber;
    SMTPUserName userName;
    SMTPPassword password;
    Str1260 subject,body;
    InteropPermission interopPermission;
    SysMailer mailer;
    SysMailerAttachments    sysMailerAttachments;
    System.Exception e;

    ;
    if (parameters.SMTPRelayServerName)
        relayServer = parameters.SMTPRelayServerName;
    else
        relayServer = parameters.SMTPServerIPAddress;
        portNumber = parameters.SMTPPortNumber;
        userName = parameters.SMTPUserName;
        password = SysEmailParameters::password();
   
        subject = "Subject line for the email";
        body = "<B>Body of the email</B>";
            body += "<br/> <B>testing</B>"; /
        body += "<br/>red</Br/>";
         body += "<br/>blue</Br/>";
         body += "<br/>orange</Br/>";
         body += "<br/>testing</Br/>";

    CodeAccessPermission::revertAssert();

    try
    {
        interopPermission = new InteropPermission(InteropKind::ComInterop);
        interopPermission.assert();
       
        FilePath = '@C//q.pdf';
        FilePath = strfmt('C:\\q.pdf');
        mailer = new SysMailer();
        mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);
        //instantiate email
        mailer.fromAddress(userName);

        mailer.tos().appendAddress("email");
        mailer.subject(subject);
        mailer.htmlBody(body);
        mailer.attachments().add(FilePath);
        mailer.sendMail();
        CodeAccessPermission::revertAssert();
        info("Email has been sent!");
    }
    catch (Exception::CLRError)

    {
    e = ClrInterop::getLastException();

    while (e)

    {
        info(e.get_Message());
        e = e.get_InnerException();
    }
    CodeAccessPermission::revertAssert();
    //info(e);
    info ("Failed to Send Email some Error occure");

No comments:

Post a Comment