//Send Email using default AX outgoing mail table ax 2012
static void MailCheck4(Args _args)
{
SysOutgoingEmailTable outgoingEmailTable;
SysOutgoingEmailData outgoingEmailData;
SysEmailItemId nextEmailItemId;
Map map;
BinData binData = new BinData();
container data;
container embeddedBinaryData;
Filename filePath;
Filename filename;
str _filename = @"filepath and name.xlsx";
Filename fileExtension;
CLRObject ex;
;
try
{
ttsBegin;
nextEmailItemId = EventInbox::nextEventId();
outgoingEmailTable.EmailItemId = nextEmailItemId;
outgoingEmailTable.IsSystemEmail = NoYes::No;
outgoingEmailTable.Sender = "";
outgoingEmailTable.SenderName = "";
outgoingEmailTable.Recipient = "";
outgoingEmailTable.Subject = SysEmailMessage::stringExpand("Test Mail", map);
outgoingEmailTable.Priority = eMailPriority::High ;
outgoingEmailTable.WithRetries = false;
outgoingEmailTable.RetryNum = 2;
outgoingEmailTable.UserId = curUserId();
outgoingEmailTable.Status = SysEmailStatus::Unsent;
outgoingEmailTable.Message = "Test mail don't reply";
outgoingEmailTable.LatestStatusChangeDateTime = DateTimeUtil::getSystemDateTime();
outgoingEmailTable.insert();
outgoingEmailData.clear();
outgoingEmailData.EmailItemId = nextEmailItemId;
outgoingEmailData.DataId = 1;
outgoingEmailData.EmailDataType = SysEmailDataType::Attachment;
binData.loadFile(_filename);
embeddedBinaryData = binData.getData();
outgoingEmailData.Data = embeddedBinaryData;
[filePath, filename, fileExtension] = Global::fileNameSplit(_filename);
outgoingEmailData.FileName = filename;
outgoingEmailData.FileExtension = fileExtension;
outgoingEmailData.insert();
info("Mail added in to queue");
ttsCommit;
}
catch
{
ex = CLRInterop::getLastException();
while(ex != null)
{
error(ex.ToString());
ex = ex.get_InnerException();
}
}
}
static void MailCheck4(Args _args)
{
SysOutgoingEmailTable outgoingEmailTable;
SysOutgoingEmailData outgoingEmailData;
SysEmailItemId nextEmailItemId;
Map map;
BinData binData = new BinData();
container data;
container embeddedBinaryData;
Filename filePath;
Filename filename;
str _filename = @"filepath and name.xlsx";
Filename fileExtension;
CLRObject ex;
;
try
{
ttsBegin;
nextEmailItemId = EventInbox::nextEventId();
outgoingEmailTable.EmailItemId = nextEmailItemId;
outgoingEmailTable.IsSystemEmail = NoYes::No;
outgoingEmailTable.Sender = "";
outgoingEmailTable.SenderName = "";
outgoingEmailTable.Recipient = "";
outgoingEmailTable.Subject = SysEmailMessage::stringExpand("Test Mail", map);
outgoingEmailTable.Priority = eMailPriority::High ;
outgoingEmailTable.WithRetries = false;
outgoingEmailTable.RetryNum = 2;
outgoingEmailTable.UserId = curUserId();
outgoingEmailTable.Status = SysEmailStatus::Unsent;
outgoingEmailTable.Message = "Test mail don't reply";
outgoingEmailTable.LatestStatusChangeDateTime = DateTimeUtil::getSystemDateTime();
outgoingEmailTable.insert();
outgoingEmailData.clear();
outgoingEmailData.EmailItemId = nextEmailItemId;
outgoingEmailData.DataId = 1;
outgoingEmailData.EmailDataType = SysEmailDataType::Attachment;
binData.loadFile(_filename);
embeddedBinaryData = binData.getData();
outgoingEmailData.Data = embeddedBinaryData;
[filePath, filename, fileExtension] = Global::fileNameSplit(_filename);
outgoingEmailData.FileName = filename;
outgoingEmailData.FileExtension = fileExtension;
outgoingEmailData.insert();
info("Mail added in to queue");
ttsCommit;
}
catch
{
ex = CLRInterop::getLastException();
while(ex != null)
{
error(ex.ToString());
ex = ex.get_InnerException();
}
}
}
thanks for this tuto but when i send mail i have an error : impossible to créate object : CRLObject can you please help me ?
ReplyDelete