Developer forum

Forum » Templates » Attach all files from a folder to an email sent from forms for editor email

Attach all files from a folder to an email sent from forms for editor email

Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi

Is it possible - in a razor template - to attach all files from a certain folder to an email sent from Forms for editor module?

I am wondering, could this be a solution to add something like this to the forms mail template?

 

mail.Attachments.Add(new System.Net.Mail.Attachment("pathToAttachment"));

 

Or does anyone have any other examples or documentation on how this could be done?

/Hans


Replies

 
Nicolai Pedersen
Reply

Hi Hans

You can use a notification subscriber:

 [Subscribe(Dynamicweb.Forms.Notifications.Frontend.OnSendMail)]
    public class FormBeingSent : NotificationSubscriber
    {
        public override void OnNotify(string notification, NotificationArgs args)
        {
            if (args == null)
                return;

            var loadedArgs = (Dynamicweb.Forms.Notifications.Frontend.OnSendMailArgs)args;

            loadedArgs.EmailMessage.Attachments.Add(new System.Net.Mail.Attachment("pathToAttachment"));

        }
    }

Be careful - it could be a lot of data in an email causing it to never reach its target. You could link to the files instead as the files are online anyways.

BR Nicolai

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi Nicolai

ok, thank you very mutch :)

will try that

Just to make sure, we are talking about doing this in a razor mailtemplates that I can select in a forms for editors module?

/Hans

 
Nicolai Pedersen
Reply

Hi Hans

You cannot do it from a Razor template. It has to be a notification subscriber which is a class written in C# or VB.

What you can do from the Razor template is to link to the files. It is a better solution if you ask me.

BR Nicolai

 

You must be logged in to post in the forum