0

just wondering how we can trigger MS Outlook new mail from client side, using ReactJs. The email should have some content (a table and some texts) in it, also with an attachment (PDF file) downloaded from server side. All the email content can be retrieved from state property 'this.state.data' (it's an array of objects).

Right now I have something below (an html way). When user clicks a button, It can open up new mail screen with subject and SentTo specified. How can I do the rest (content + attachment)?

<button type="button" className="btn btn-default"><a href="mailto:this.guy@gmail.com?subject=Test">Send Out Email</a></button>

For attachment, I need to (probably) write a get method to download from server first. Then how can we attach it to email?

I already know how to download it from server and display it on another tab (it works fine):

  handleDownload = (path) => {
    window.open(
        "/myController/GetFileFromServer?filePath=" + path,
        "_blank"
    );

Alternatively, I can also send email via server side, it feels easier for me. However, users likely need to enrich the email manually first before sending. Hence I thought client side would be more suitable for my case.

xzk
  • 827
  • 2
  • 18
  • 43
  • Just saw this post..seems impossible to attach files in email using mailto..https://stackoverflow.com/questions/5233556/using-mailto-to-send-email-with-an-attachment-html-or-jsf – xzk Feb 14 '18 at 02:57

1 Answers1

1

As per this answer it is not possible to specify attachments with a mailto:

However, as per this answer you can add email content along with subject line

I'd suggest you show a text area for user to enter in email content and then send an email from the server

Varinder
  • 2,634
  • 1
  • 17
  • 20
  • Thanks Varinder! Yea I also found that post which says attachment is not possible with mailTo. Probably I have to drop that idea. For the email content, I do have to let users to review/enrich before sending, and it's really a case by case situation and a generic textarea may not help. Also, the email which I need to send is quite 'colourful', with a proper table, paragraphs, highlighting, bold, underline etc.., adding the content along with subject line seems difficult to me. – xzk Feb 14 '18 at 03:04
  • I see, handling this on the server side may be less challenging – Varinder Feb 14 '18 at 03:06