// Steps to send Automatic appointment to Mail id by using outlook through X++
static void OutlookAppointment(Args _args)
{
COM sysOutlookCollection;
COM receipiants;
COM collection;
COMVariant comStartDate = new COMVariant();
COMVariant comEndDate = new
COMVariant();
COM c;
#SysOutLookCOMDEF
#define.mapi("MAPI")
#define.outlook("Outlook.Application")
COM sysOutlook;
COM sysOutlookNameSpace;
COM sysOutlookMAPIFolder;
sysOutlook = new COM(#outlook);
sysOutlookNameSpace = sysOutlook.getNamespace(#mapi);
sysOutlookNameSpace.logon();
sysOutlookMAPIFolder = sysOutlookNameSpace.getDefaultFolder(#OlDefaultFolders_olFolderTasks);
collection = sysOutlookMAPIFolder.items();
c = collection.add();
comStartDate.date(today());
comStartDate.time(str2Time( "10:40:00"));
comEndDate.date(today());
comEndDate.time(str2Time( "10:45:00"));
c.subject("Meeting regd Microsoft Dynamics AX 2012");
c.body("Lets discuss on whats new in DAX 2012");
c.save();
if (c)
{
receipiants = c.Recipients();
receipiants.add(" Desired mail Id");
receipiants.ResolveAll();
c.assign();
//c.display();
c.send();
info("The action is created in Microsoft Outlook");
}
else
throw error("@SYS31969");
sysOutlookNameSpace.logoff();
}
static void OutlookAppointment(Args _args)
{
COM sysOutlookCollection;
COM receipiants;
COM collection;
COMVariant comStartDate = new COMVariant();
COMVariant comEndDate = new
COMVariant();
COM c;
#SysOutLookCOMDEF
#define.mapi("MAPI")
#define.outlook("Outlook.Application")
COM sysOutlook;
COM sysOutlookNameSpace;
COM sysOutlookMAPIFolder;
sysOutlook = new COM(#outlook);
sysOutlookNameSpace = sysOutlook.getNamespace(#mapi);
sysOutlookNameSpace.logon();
sysOutlookMAPIFolder = sysOutlookNameSpace.getDefaultFolder(#OlDefaultFolders_olFolderTasks);
collection = sysOutlookMAPIFolder.items();
c = collection.add();
comStartDate.date(today());
comStartDate.time(str2Time( "10:40:00"));
comEndDate.date(today());
comEndDate.time(str2Time( "10:45:00"));
c.subject("Meeting regd Microsoft Dynamics AX 2012");
c.body("Lets discuss on whats new in DAX 2012");
c.save();
if (c)
{
receipiants = c.Recipients();
receipiants.add(" Desired mail Id");
receipiants.ResolveAll();
c.assign();
//c.display();
c.send();
info("The action is created in Microsoft Outlook");
}
else
throw error("@SYS31969");
sysOutlookNameSpace.logoff();
}
Hi,
ReplyDeleteWe want to run this in batch without outlook. Is it possible ? Can you please provide me a sample code ?
Regards,
Sorry late reply..
DeleteBelow code
//Mail SMTP
Set permissionSet;
int i;
System.Exception e;
str 100 fileName;
SysEmailMessageTable message;
Dialog dialog;
DialogField dfFileName;
str mailServer;
int mailServerPort;
str testmail;
System.Net.Mail.SmtpClient mailClient;
System.Net.Mail.MailMessage mailMessage;
System.Net.Mail.MailAddress mailFrom;
System.Net.Mail.MailAddress mailTo;
System.Net.Mail.MailAddressCollection mailToCollection;
System.Net.Mail.MailAddressCollection mailCCCollection;
System.Net.Mail.AttachmentCollection mailAttachementCollection;
System.Net.Mail.Attachment mailAttachment;
;
//filename = @"C:\Users\name\Desktop\test.txt";
permissionSet = new Set(Types::Class);
permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
//permissionSet.add(new FileIOPermission(filename, 'rw'));
CodeAccessPermission::assertMultiple(permissionSet);
mailServer = SysEmaiLParameters::find(false).SMTPRelayServerName;
mailServerPort = SysEmaiLParameters::find(false).SMTPPortNumber;
mailClient = new System.Net.Mail.SmtpClient(mailServer, mailServerPort);
testmail = "";//Include From EMail Address
mailFrom = new System.Net.Mail.MailAddress(testmail);
testmail = ""; //Include To mail address
mailTo = new System.Net.Mail.MailAddress(testmail);//strLTrim(strRTrim(custTable.email())));
mailMessage = new System.Net.Mail.MailMessage(mailFrom, mailTo);
mailToCollection = mailMessage.get_To();
mailMessage.set_Priority(System.Net.Mail.MailPriority::High);
mailMessage.set_Subject("Hi");
//mailAttachementCollection = mailMessage.get_Attachments();
//mailAttachment = new System.Net.Mail.Attachment(fileName);
//mailAttachementCollection.Add(mailAttachment);
mailClient.SendAsyncCancel();
mailClient.Send(mailMessage);
mailMessage.Dispose();
info("Mail Sent");
CodeAccessPermission::revertAssert();