Send email in code using template with attachments

Dmitriy Nenazhenko asked on August 10, 2016 10:53

Hi, I am trying to send email through this

var email = "test@test.test";
var emailMessage = new EmailMessage();
emailMessage.Recipients = email;
EmailSender.SendEmail("MySite", emailMessage, "WhitePaper", MacroResolver.GetInstance(), true);

But in this template "WhitePaper" I have an attachment. When email is sent I cannot see any attachments inside. How can I get attachments from email template.

Correct Answer

Anton Grekhovodov answered on August 10, 2016 12:27

Hi Dmitriy,

Template attachments are saved in CMS_MetaFile table. So if you want to get all attachments, use this code:

var emailTemplate = EmailTemplateProvider.GetEmailTemplate("yourtemplatename", "yoursitename");
MetaFileInfoProvider.GetMetaFiles(emailTemplate.TemplateID, "cms.emailtemplate", "Template", "", "");
1 votesVote for this answer Unmark Correct answer

Recent Answers


Roman Hutnyk answered on August 10, 2016 11:44

EmailMessage class has Attachments field. I belive you have to set it up in order to include attachment into your email.

0 votesVote for this answer Mark as a Correct answer

Dmitriy Nenazhenko answered on August 10, 2016 11:59

But how can I get attachments from email template?

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on August 10, 2016 12:45

You have to control what you are going to send in an email. How are you sending this email?

What event is triggering this email?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.