首页 文章

在Node.js中发送电子邮件? [关闭]

提问于
浏览
258

我最近开始编程我的第一个node.js.但是,我发现我无法创建直接发送到我的电子邮件的联系人表单,因为我找不到任何能够发送电子邮件的节点的模块 .

有谁知道node.js电子邮件库或示例联系表单脚本?

11 回答

  • 48

    Nodemailer基本上是一个模块,使您能够在Node.js中编程时轻松发送电子邮件 . 有一些关于如何在http://www.nodemailer.com/使用Nodemailer模块的很好的例子 . 有关如何安装和使用Nodemailer基本功能的完整说明,请参见此链接 .

    我个人在使用npm安装Nodemailer时遇到了麻烦,所以我刚刚下载了源代码 . 有关npm安装和下载源的说明 .

    这是一个非常简单的模块,我建议任何想要使用Node.js发送电子邮件的人 . 祝好运!

  • 131

    node-email-templates是一个更好的选择:https://github.com/niftylettuce/node-email-templates

    它也支持Windows

  • 8

    看看emailjs

    在浪费了大量时间尝试使用大型附件进行nodemailer工作之后,发现了emailjs并且从此开心 .

    它支持使用普通的File对象发送文件,而不是像nodemailer所要求的那样使用巨大的Buffers . 意味着你可以将它链接到,例如,强大的将附件从html表单传递给邮件程序 . 它还支持排队..

    总而言之,不知道为什么nodejitsu ppl选择了nodemailer来 Build 他们的版本,emailjs更加先进 .

  • 3

    使用nodemailer模块完成代码以发送电子邮件

    var mailer = require("nodemailer");
    
    // Use Smtp Protocol to send Email
    var smtpTransport = mailer.createTransport("SMTP",{
        service: "Gmail",
        auth: {
            user: "gmail_id@gmail.com",
            pass: "gmail_password"
        }
    });
    
    var mail = {
        from: "Yashwant Chavan <from@gmail.com>",
        to: "to@gmail.com",
        subject: "Send Email Using Node.js",
        text: "Node.js New world for me",
        html: "<b>Node.js New world for me</b>"
    }
    
    smtpTransport.sendMail(mail, function(error, response){
        if(error){
            console.log(error);
        }else{
            console.log("Message sent: " + response.message);
        }
    
        smtpTransport.close();
    });
    
  • 24

    @ JimBastard接受的答案似乎已过时,我看了一下,邮件库已经超过7个月未被触及,列出了几个错误,并且不再在npm注册 .

    nodemailer当然看起来是最好的选择,但是在这个帖子的其他答案中提供的网址都是404' .

    nodemailer声称支持轻松插入gmail,hotmail等,并且还有非常漂亮的文档 .

  • 145

    你总是可以使用AlphaMaildisclosure: I'm one of the developers behind it ) .

    只需使用NPM安装:

    npm install alphamail
    

    注册一个AlphaMail帐户 . 获取令牌,然后您可以开始使用AlphaMail服务发送 .

    var alphamail = require('alphamail');
    
    var emailService = new alphamail.EmailService()
        .setServiceUrl('http://api.amail.io/v1/')
        .setApiToken('YOUR-ACCOUNT-API-TOKEN-HERE');
    
    var person = {
        id: 1234,
        userName: "jdoe75",
        name: {
            first: "John",
            last: "Doe"
        },
        dateOfBirth: 1975
    };
    
    emailService.queue(new alphamail.EmailMessagePayload()
        .setProjectId(12345) // ID of your AlphaMail project (determines template, options, etc)
        .setSender(new alphamail.EmailContact("Sender Company Name", "from@example.com"))
        .setReceiver(new alphamail.EmailContact("John Doe", "to@example.org"))
        .setBodyObject(person) // Any serializable object
    );
    

    在AlphaMail GUI(Dashboard)中,您将能够使用您发送的数据编辑模板:

    <html>
        <body>
            <b>Name:</b> <# payload.name.last " " payload.name.first #><br>
            <b>Date of Birth:</b> <# payload.dateOfBirth #><br>
    
            <# if (payload.id != null) { #>
                <a href="http://company.com/sign-up">Sign Up Free!</a>
            <# } else { #>
                <a href="http://company.com/login?username=<# urlencode(payload.userName) #>">Sign In</a>
            <# } #>
        </body>
    </html>
    

    模板以Comlang编写,它是专为电子邮件设计的简单模板语言 .

  • 6

    成熟,易于使用,并且如果不简单则具有许多功能:Nodemailer:https://github.com/andris9/nodemailer(注意正确的URL!)

  • 9

    Nodemailer模块是在node.js中发送电子邮件的最简单方法 .

    试试这个示例示例表单:http://www.tutorialindustry.com/nodejs-mail-tutorial-using-nodemailer-module

    附加信息:http://www.nodemailer.com/

  • 2

    npm 有几个包,但还没有达到1.0 . 最佳选择来自 npm list mail

    email@0.2.2
    mail@0.1.1
    mailer@0.3.0
    
  • 3

    您肯定希望使用https://github.com/niftylettuce/node-email-templates,因为它支持nodemailer / postmarkapp并且内置了漂亮的异步电子邮件模板支持 .

  • 64

    campaign是一个用于在Node中发送电子邮件的综合解决方案,它带有一个非常简单的API .

    你这样实例 .

    var client = require('campaign')({
      from: 'you@gmail.com'
    });
    

    要发送电子邮件,您可以使用Mandrill,这是免费且非常棒的 . 只需设置您的API密钥,如下所示:

    process.env.MANDRILL_APIKEY = '<your api key>';
    

    (如果您想使用其他提供商发送电子邮件,请查看文档)

    然后,当您要发送电子邮件时,您可以这样做:

    client.sendString('<p>{{something}}</p>', {
      to: ['someone@gmail.com', 'someone.else@gmail.com'],
      subject: 'Some Subject',
      preview': 'The first line',
      something: 'this is what replaces that thing in the template'
    }, done);
    

    GitHub回购有pretty extensive documentation .

相关问题