Hi alex,
Thanks for your reply,
I have done these initialization for sysMailerclass, ComInterop permission, and all mail addresses are given properly, but also the AX is getting closed.
Code snippet as follows,
[code]
void reset()
{
InteropPermission permission= new InteropPermission(InteropKind::ComInterop);
;
permission.assert();
mail = new SysMailer();
codeAccessPermission::revertAssert();
mail.SMTPRelayServer(sysEmailParameters.SMTPRelayServerName,
sysEmailParameters.SMTPPortNumber,
sysEmailParameters.SMTPUserName,
sysEmailParameters.SMTPPassword,
sysEmailParameters.NTLM);
pdfInvoice = new Set(Types::String);
excelInvoice = new Set(Types::String);
pdfPackingSlip = new Set(Types::String);
excelPackingSlip = new Set(Types::String);
cartonsTotal = 0;
grossWeightTotal = 0;
mailAttachmentSize = 0;
}
public Boolean sendMail(Email _emailId, Container _shipments)
{
int counter;
int noOfPDFAttachmentsForInvoice, noOfExcelAttachmentsForInvoice, noOfPDFAttachmentsForPackingSlip, noOfExcelAttachmentsForPackingSlip;
Str mailBody;
Str fileName;
int recordCounter,dataCounter;
CNLIN_FreightForwarderInfo freightForwarderInfoTable;
CNLIN_ShipmentIds shipmentIds;
Boolean isExcelAttached, isPDFAttached, sendMail, isFileAttached;
int attachmentSize, i;
Container limitedAttachment, splitedAttachment;
void sendMailImmediately()
{
if(mailAttachmentSize > (maxAttachmentSize * 1000000))
{
mailBody += this.mailBody(recordCounter, _shipments, counter);
this.sendSplittedMail(_emailId, conpeek(conpeek(_shipments,1),3), mailBody);
this.reset();
mail.fromAddress(parm.CNLIN_HKEmailId);
mail.ccs().appendAddress(parm.CNLIN_HKEmailId);
mail.tos().appendAddress(_emailId);
}
}
;
if(!isBatchProcess)
{
sysEmailParameters = SysEmailParameters::find(false);
maxAttachmentSize = sysEmailParameters.MaxEmailAttachmentSize;
//maxAttachmentSize in megabytes
if (maxAttachmentSize < 1)
maxAttachmentSize = #maxAttachmentSizeDefault;
}
this.reset();
parm = SalesParameters::find();
if(!parm.CNLIN_HKEmailId)
{
throw error("@CHK673"); // HK Email Id cannot be blank
}
else
{
mail.fromAddress(parm.CNLIN_HKEmailId);
mail.ccs().appendAddress(parm.CNLIN_HKEmailId);
}
mail.tos().appendAddress(_emailId);
for(counter = 1; counter <= conlen(_shipments); counter++)
{
sendMail = isBatchProcess? conpeek(conpeek(_shipments, counter), 21): conpeek(conpeek(_shipments, counter), 17);
if(_emailId == conpeek(conpeek(_shipments, counter), 1)
&& NoYes::Yes == conpeek(conpeek(_shipments, counter), 6)
&& sendMail)
{
recordCounter++;
isPDFAttached = isBatchProcess? conpeek(conpeek(_shipments, counter), 18): conpeek(conpeek(_shipments, counter), 2);
isExcelAttached = isBatchProcess? conpeek(conpeek(_shipments, counter), 19): conpeek(conpeek(_shipments, counter), 15);
salesId = conpeek(conpeek(_shipments, counter), 26);
if(NoYes::Yes == isPDFAttached)
{
// Attaching Invoice PDF file
fileName = this.generatePDForExcelInvoice(conpeek(conpeek(_shipments, counter), 4), #pdf, strfmt("@CHK924",conpeek(conpeek(_shipments, counter), 22))); // %1
if(fileName)
{
sendMailImmediately();
mail.attachments().add(fileName);
noOfPDFAttachmentsForInvoice++;
}
// Attaching Packing Slip PDF file salesTable.SalesId
fileName = this.generatePDForExcelPackingSlip(conpeek(conpeek(_shipments, counter), 4), #pdf, strfmt("@CHK924",conpeek(conpeek(_shipments, counter), 23))); // %1
if(fileName)
{
sendMailImmediately();
mail.attachments().add(fileName);
noOfPDFAttachmentsForPackingSlip++;
}
}
if(NoYes::Yes == isExcelAttached)
{
// Attaching Invoice Excel file
fileName = this.generatePDForExcelInvoice(conpeek(conpeek(_shipments, counter), 4), #excel, strfmt("@CHK924",conpeek(conpeek(_shipments, counter), 24))); // %1
if(fileName)
{
sendMailImmediately();
mail.attachments().add(fileName);
noOfExcelAttachmentsForInvoice++;
}
// Attaching Packing Slip Excel file
fileName = this.generatePDForExcelPackingSlip(conpeek(conpeek(_shipments, counter), 4), #excel, strfmt("@CHK924",conpeek(conpeek(_shipments, counter), 25))); // %1
if(fileName)
{
sendMailImmediately();
mail.attachments().add(fileName);
noOfExcelAttachmentsForPackingSlip++;
}
}
mailBody += this.mailBody(recordCounter+1, _shipments, counter);
}
}
if(recordCounter > 0)
{
this.sendSplittedMail(_emailId, conpeek(conpeek(_shipments,1),3), mailBody);
info(strfmt("@CHK912", noOfPDFAttachmentsForInvoice)); // No of Invoice PDF attached: %1
info(strfmt("@CHK913", noOfExcelAttachmentsForInvoice)); // No of Invoice Excel attached: %1
info(strfmt("@CHK914", noOfPDFAttachmentsForPackingSlip)); // No of Packing Slip PDF attached: %1
info(strfmt("@CHK915", noOfExcelAttachmentsForPackingSlip)); // No of Packing Slip Excel attached: %1
return true;
}
else
{
return false;
}
}
[\code]