This is the code to send email from axapta with attachment.You can write this code in method of any class and simple call it.
InteropPermission IntCPermission = new InteropPermission(InteropKind::ComInterop);
InteropPermission IntCPermission1 = new InteropPermission(InteropKind::ClrInterop);
InteropPermission IntCPermission2 = new InteropPermission(InteropKind::DllInterop);
str body,mailto, mailfrom;
System.Net.Mail.AttachmentCollection attachementCollection;
str FileName;
FileIOPermission FilePerm;
SysMailer mailer;
SysEmailParameters parameters = SysEmailParameters::find();
;
try
{
IntCPermission.assert();
mailer = new SysMailer();
if (parameters.SMTPRelayServerName)
{
mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
}
else
{
mailer.SMTPRelayServer(parameters.SMTPServerIPAddress,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
}
mailto = 'to email address';
mailfrom = SysEmailParameters::find().SMTPUserName;
mailfrom = 'sender email address';
mailer.fromAddress(SysEmailParameters::find().SMTPUserName);
mailer.tos().appendAddress(mailto);
body= "email message";
mailer.htmlBody(body);
mailer.quickSend(mailfrom,mailto,"Title of Email",'','D:\\Filenm.pdf');
return true;
}
catch(Exception::CLRError)
{
return false;
}