Monday, August 28, 2017

EMail with outgoing email table as system std

static void MailTest_san(Args _args)
{
    VendTable       vendTable;
    void SendEmail(Str _Recipitent,Str    _subject,Str _message,VendTable    _vendTable)
    {
        SysOutgoingEmailTable               outgoingEmailTable;
        SysOutgoingEmailData                outgoingEmailData;
        SysEmailItemId                      nextEmailItemId;
        Map                                 map;
        BinData                             binData = new BinData();
        container                           data;
        container                           embeddedBinaryData;
        Filename                            filePath;
        Filename                            filename;
        Filename                            fileExtension;
        CLRObject                           ex;
        ;
        try
        {
            map = new Map(Types::String, Types::String);
            map.insert('Supplier Id', _vendTable.AccountNum);
            map.insert('Supplier Name', _vendTable.name());
            map.insert('Supplier Type', _vendTable.SupplierType);
            map.insert('Supplier Category', _vendTable.SupplierCategory);
            map.insert('Supplier Sub Category', _vendTable.SupplierSubCategory);
            map.insert('Contact Details',strFmt("%1/%2",_vendTable.phone(),_vendTable.email()));
            ttsBegin;
            nextEmailItemId                                 = EventInbox::nextEventId();
            outgoingEmailTable.EmailItemId                  = nextEmailItemId;
            outgoingEmailTable.IsSystemEmail                = NoYes::No;
            outgoingEmailTable.Sender                       = "test@gmail.com";
            outgoingEmailTable.SenderName                   = "ADNEC";
            outgoingEmailTable.Recipient                    = _Recipitent;
            outgoingEmailTable.Subject                      = _subject;
            outgoingEmailTable.Priority                     = eMailPriority::High ;
            outgoingEmailTable.WithRetries                  = false;
            outgoingEmailTable.RetryNum                     = 2;
            outgoingEmailTable.UserId                       = curUserId();
            outgoingEmailTable.Status                       = SysEmailStatus::Unsent;
            outgoingEmailTable.Message                      = SysEmailMessage::stringExpand(_message, map);
            outgoingEmailTable.LatestStatusChangeDateTime   = DateTimeUtil::getSystemDateTime();
            outgoingEmailTable.insert();
            ttsCommit;
        }
        catch
        {
            ex = CLRInterop::getLastException();
            while(ex != null)
            {
                error(ex.ToString());
                ex = ex.get_InnerException();
            }
        }
    }
    ;
    while select * from vendTable
            //where vendTable.AccountNum == "vendornum"
    {
        SendEmail("senderemail address",strFmt("%1 - Suplier Id %2",SysEmailMessageTable::find("emailtest","en-us").Subject,vendTable.AccountNum),
                                                SysEmailMessageTable::find("emailtest","en-us").Mail,vendTable);
    }
}

No comments:

Post a Comment

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...