Hello, I’ve pieced this together from various posts around here,
The problem I’m having is in the foreach, the attachments in the foreach don’t attach and I get an exception error
Does anyone have any tips??
var mailer = this.GetMailer(async: true);
var message = new Ice.Mail.SmtpMail();
message.SetFrom("Purchasing | Treadwell Group<do-not-reply@test.com.au>");
message.SetTo(sendTo);
message.SetBcc("lrb@test.com.au; ");
message.SetSubject(eSubject);
message.SetBody(eBody);
Dictionary<string, string> attachments = new Dictionary<string, string>();
attachments.Add(fileName, filePath); // << this one attaches
if(sender.CheckBox05 == true)
{
var atts = Db.XFileRef.Where(f => f.Company == Session.CompanyID && f.DocTypeID == "Supplier" && Db.XFileAttch.Any(x => x.XFileRefNum == f.XFileRefNum && x.Key1 == poNum.ToString() && (x.RelatedToFile == "PODetail" || x.RelatedToFile == "POHeader"))).ToList();
try
{
if(atts != null)
{
foreach(var att in atts)
{
filePath = att.XFileName;
fileName = att.XFileDesc;
attachments.Add(fileName, filePath); //<< these ones don't attach
}
}
}
catch (Exception ex)
{
this.PublishInfoMessage(ex.ToString(),Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual,"","");
}
}
mailer.Send(message, attachments);
}
Information Message Caught:
Information Message Detail:
Version: 0
Program:
Method:
User:
Company:
Site:
Message: System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Epicor.Customization.Bpm.DB78580E63AE594432ADF76882F6685F7D.PostTranDirective_PO_Send_C7AA3314718B4A789A98A74563B7F83B.A001_CustomCodeAction()
Severity: Error