Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I need to send an email containing attachments when the order is finalized. The customer has to download and print a Pdf ticket and use it to access a purchased event. I tried with the EmailTemplateService in the context of the NotificationEventHandlerBase<OrderFinalizedNotification>, but I'm not able to find a way to include one or more files as email attachments. Do you have any suggestions?
You'll need to hook into the email sending pipeline to add the attachment to the email message. We have a basic example of exactly this in the docs for pipelines https://vendr.net/docs/core/1.8.0/key-concepts/pipelines/#example-pipeline-task
Hopefully this gives you enough info to get it working, but let me know if there is anything that isn't clear.
PS the EmailSendPipelineArgs should provide details of the email template being sent so you can use that to only add the attachment if it's the confirmation email.
Hi Matt, thanks for the help, I hadn't read that section in the documentation. I tried to use the Pipelines, and in debug I see that the code runs correctly when a confermation email is sent. However, the attachment - which is an existing file on my PC - is not sent using the following code. Is there anything else I'm missing?
public override PipelineResult<EmailContext>
if (args.EmailContext.EmailTemplate.Alias == Constants.OrderConfirmationEmail)
var order = args.EmailContext.Model as OrderReadOnly;
if (order != null)
var attachment = new Attachment("C:\\test.txt");
When you say you can see the code runs, does the attachment show in the mail messages attachments collection? My initial guess would be a) does the text file exist and b) does the sending process have permission to access it.
I'll be more precise. The path is correct, the file is detected and it is correctly added to the collection. If I look at the EmailContext object in the last line return Ok(args.EmailContext); I see that the Attachments property contains my document. However, I don't see the attachment in the email received. Is it possible that the MailMessage.Attachments property is replaced somewhere else - later - in the code?
And how are you attaching your pipeline task?
Ok, my guess is that you've copied the docs and I've just realized, the example in the docs isn't going to work as the sending of the email is part of the pipeline, so appending your task on the end is essentially going to run your task after the email is sent.
You'll need to use something like this instead.
Oh, you guessed it. With your code, the attachment is added before and everything is working. Thank you!
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted