简体   繁体   English

通过带有附件的JavaScript发送邮件

[英]Send mail via javascript with attachements

I have a requirement to send the a file(pdf/image) to specific users from my page. 我需要将文件(pdf / image)从我的页面发送给特定用户。 How can i achieve this with javascript? 如何使用javascript实现此目的? I do not want to hard-code the from mail address as i want to send the file from the user who logged on to the page. 我不想对发件人的邮件地址进行硬编码,因为我想从登录页面的用户发送文件。

Open and add the attachment to my default mail client is also acceptable for me. 打开附件并将其添加到我的默认邮件客户端对我来说也是可以接受的。 I have searched many sites but couldn't find an answer to the scenario. 我搜索了许多站点,但找不到该方案的答案。 Anyone please help me through this. 任何人都可以帮助我。

You will need to do a POST or GET ajax call to a server that has a kind of email sending technology like nodemailer from node.js or php. 您将需要对具有某种电子邮件发送技术(例如来自node.js或php的nodemailer)的服务器进行POST或GET ajax调用。

First set up a node.js server. 首先设置一个node.js服务器。 Then npm install nodemailer and configure it to your requirements. 然后, npm install nodemailer并将其配置为您的要求。

In case you don't have access to a server, you can send emails directly within javascript using a platform like mailgun.com or mailchimp.com. 如果您无权访问服务器,则可以使用mailgun.com或mailchimp.com之类的平台直接在javascript中发送电子邮件。 Here is how you would do it with mailgun (that's what I use): 这是使用mailgun的方式(这就是我使用的方式):

  1. Create an account in mailgun.com, you will get 10.000 emails free each month if you verify your domain else 300. 在mailgun.com中创建一个帐户,如果您验证自己的域(其他为300个),则每个月将免费获得10.000封电子邮件。

  2. Learn to use the api here mailgun send email api . 在此处了解如何使用api mailgun发送电子邮件api First you will have to authenticate , and then you will be able to send emails. 首先,您必须进行身份验证 ,然后才能发送电子邮件。

Try it and let me know if you where able to send those emails. 尝试一下,让我知道您是否可以发送这些电子邮件。 Remember that you don't need a server if you use the mailgun API or any other but I recommend you to set up a node.js server with nodemailer for more control. 请记住,如果您使用mailgun API或任何其他工具,则不需要服务器,但是我建议您使用nodemailer来设置node.js服务器以进行更多控制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM