Developer forum

Forum » Development » Form: Send email with attachment (Uploaded item)

Form: Send email with attachment (Uploaded item)

Thaw Htun Lynn
Reply

Hi,

I am trying to create a form, with "FIle" field, where user can upload the file and submit the form. I've also configured to send email when the user submit the form.

I've received the email when the user submit the form but it only displayed the location file is uploaded instead of attaching it. Is there any way that we can attach the uploaded file into the email as attachment?

And also, from the Mail Server setting, we are setting up email to sent mails from the server. If we have multiple websites, can we have different mail server for different websites?

Thanks alot,

Thaw

FormWithFields.jpg

Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Thaw

You cannot attach files to the mail by default. I can see from the dump, that you are using the 'old' forms module. You should be using "Forms for editors" found in 8.6+:

http://manual.dynamicweb-cms.com/Dynamicweb-On-line-Manual/Modules/Forms-for-editors.aspx

Using that, you can have a link to the uploaded file in the receipt template so it can be downloaded directly.

Using a notification subscriber in forms for editors, it is also possible to make some code that attaches the file to the mail.

It is not possible to have different mail servers for a solution.

BR Nicolai

Votes for this answer: 1
 
Hans Ravnsfjall
Reply

Hi

I am looking for at similar thing. Where can i find a temple for the Receipt, what shall it contain etc? Is there at tag for rendering the text in the textbox and so on?

 

Regards, Hans

 
Rui Silva
Reply

I also need to make a custom e-mail with an attachment.

Can you add an example of the notification to be watched so I can add the attachment to the MailMessage object.

 

Best,

Rui Silva

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
This post has been marked as an answer

Hi Rui,

The following subscriber should work for Forms for Editors:

  [Subscribe(Notifications.Frontend.OnSendMail)]
  public class AttachEmail : NotificationSubscriber
  {
    public override void OnNotify(string notification, NotificationArgs originalArgs)
    {
      var args = (Notifications.Frontend.OnSendMailArgs)originalArgs;
    }
  }


You should be able to grab the file(s) from the HttpContext.Current.Request although they may also be available on args.Submit.FieldValues; haven't checked this yet.

Imar

Votes for this answer: 1
 
Rui Silva
Reply

Thanks Imar!

That's exactly what I need.

 
Marie Louise Veigert
Reply

Hi Imar,

I'm trying to do something like this, but could only find this in version 9+.

 

Do you know if something similar is possible in version 8+? :)

 

BR

Marie Louise

 
Nicolai Pedersen
Reply
This post has been marked as an answer

It is the same in Dynamicweb 8. Just in Dynamicweb.Modules.dll instead of Dynamicweb.Forms.dll

BR Nicolai

Votes for this answer: 1
 
Marie Louise Veigert
Reply

Hi Nicolai,

I have used Dynamicweb.Modules.dll before, when I needed to override the redirect, so that part of the problem should be solved :)

But I need to know how to listen on 'OnSendMail', which Imar refeered to, so I can attach the files before the mail are send :) 

Is that part possible in Dynamicweb 8? Because it doesn't seem to exist in the API for Dynamicweb 8.

 
Nicolai Pedersen
Reply

Hi Marie

Like this - make sure you have an up to date DW8!

[Subscribe(Dynamicweb.Modules.Forms.Notifications.Frontend.OnSendMail)]
  public class AttachEmail : NotificationSubscriber
  {
    public override void OnNotify(string notification, NotificationArgs originalArgs)
    {
      var args = (Notifications.Frontend.OnSendMailArgs)originalArgs;
    }
  }

 
Marie Louise Veigert
Reply

Hi Nicolai,

When you say up to date, which version?

We are currently running version 8.8.1.32, where the Modules doesn't contains a 'Forms'.

I have updated the latest API /  Visual Studio templates from the download section.

BR

Marie Louise

 
Nicolai Pedersen
Reply

That notification was added with TFS#16963, in 8.7.0.0

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi

Looking for a similar solution, but gues this can´t be done with a razortemplate, right?

Any chance of getting this as a "standard" feature, so that you eg. could select on the module settings if files/upload fields should be uploaded and/or attached in the mail notifier?

/Hans

 
Nicolai Pedersen
Reply

So the file uploaded from the forms should be attached to the email to the website owner?

We have forms for editors improvements on the roadmap - so this feature could be one of them.

BR Nicolai

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

We've had multiple customers request the files to be attached to email over the years. Of course there are limitations to file size and some mail servers may block certain files, but to have the option to do so (without losing current functionality) would be a 'plus'.

 

You must be logged in to post in the forum