1

Let's say I have a website where there is a button. When you click on this button the website will send the current page html (either as the body of an email or as an attachment ex: index.html) to a specific email address. Is this possible? If so, how? (I want to do it in either with html tags or javascript).

It's like sending a form but instead you send an html page.

BreezeWind
  • 618
  • 1
  • 9
  • 18
  • You cannot directly send an email using javascript. You can however accomplish this using nodejs https://stackoverflow.com/questions/7381150/how-to-send-an-email-from-javascript – sagar1025 May 23 '20 at 19:21
  • there is the mailto html tag no? – BreezeWind May 23 '20 at 19:25
  • @Nassims, `mailto` in HTML is just a custom prefix for an `href` target. You can configure it on anchor tags like, `Email John`, and most user-agents (browsers) will then open the system's default mailing client when that link is clicked. You can also make that populate with specific text by including `mailto:bob@example.com?subject=some subject value&body=some body value`, but the contents must be `text/plain`. Although, here is an interesting possible solution: [StackOverflow: mailto link with HTML body](https://stackoverflow.com/a/46699855/2694511). – Spencer D May 23 '20 at 19:51
  • Did you get the problem solved? – shiv May 27 '20 at 18:32

1 Answers1

0

What you're describing looks to be a use case for NodeMailer. Assumption here is that you're using Node.js as your backend. There are many options for other languages pypi-mailer being a common option for python.

Regardless, you would need to have a html form (or a default option of email)

<form action="/sendMail">
  <label for="email">Email: </label><br>
  <input type="text" id="email" name="email" value="Enter your email"><br>
  <input type="submit" value="Submit">
</form> 

<p>If you click the "Submit" button, the form-data will be send to an endpoint /sendMail".</p> 

Then you would need Javascript on the front-end to actually get the object. I believe this answer is what you're looking for here.

This link explains how to actually use nodemailer to send an email.

Hope this helps!

shiv
  • 165
  • 1
  • 20