Add An Attachment or Hyperlink Within BPM Email?

,

Is it possible to create a BPM that sends an email with an attachment or hyperlink to a file?

If you are storing attachments on the shared drive then you can add the file full location as Hyperlink in the email. You will get a path from table ice.XFileRef and ice.XFileAttch.

1 Like

I’ve just finished building this kind of BPM, here is the email and attachment part of the code

This grabs the PO that gets printed to a file location and it grabs any attachments that are attached to the PO Entry screen and sends it in an email from the BPM to the supplier

    var mailer = this.GetMailer(async: false);
    var  message = new Ice.Mail.SmtpMail();
   // message2.SetFrom(fromAddress);
    message.SetFrom("Purchasing | Treadwell Group<do-not-reply@xyz.com.au>");
    //message.SetTo(sendTo);
    message.Priority = System.Net.Mail.MailPriority.High;
    //message.SetCC(ordEntPer + "@xyz.com.au");
    message.SetBcc("lrb@xyz.com.au; ");
   // message.SetReplyTo(ordEntPer + "@xyz.com.au");
    message.SetSubject(eSubject);
    message.SetBody(eBody);
  
    Dictionary<string, string> attachments = new Dictionary<string, string>();
    if(sender.CheckBox05 == true)
    {
    var atts = Db.XFileRef.Where(f => f.Company == Session.CompanyID && Db.XFileAttch.Any(x => x.XFileRefNum == f.XFileRefNum && x.Key1 == poNum.ToString() && (x.RelatedToFile == "PODetail" || x.RelatedToFile == "POHeader"))).ToList();
    if(atts != null)
    {
    foreach(var att in atts)
    {
    string filePaTha = att.XFileName;
    var fileNamEa = filePaTha.ToString().Split('\\')[4];
    attachments.Add(fileNamEa, filePaTha);
    }
    }
    }
     //attachments.Add(pdf, folder + pdf);
     attachments.Add(fileName, filePath);
     mailer.Send(message, attachments);
3 Likes

Hold off using the code I posted above, it only works if there is only 1 attachment found in the XFileAttch Db, if there is more than 1 found it throws and exception, I’ll edit this later with the exception details

All good, there were 2 files named the same causing it to fail :man_facepalming: :man_facepalming: