te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Sending email from own server to the internets - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Sending email from own server to the internets - Stack Overflow

programmeradmin3浏览0评论

I have set up an email server on my host. It's basically a SMTP server that listens on port 25.

const recvServer = new SMTPServer({
  requireTLS: true,
  authOptional: true,
  logger: true,      
  onConnect(session, callback) {
    return callback();
  },

  onMailFrom(address, session, callback) {
    console.log('from', address, session);
    return callback();
  },    

  onData(stream, session, callback) {
    console.log('new msg');
    let message = '';
    stream.on('data', chunk => {
      message += chunk;
    });

    stream.on('end', () => {

      callback(null, 'Message queued');
      simpleParser(message)
        .then(parsed => {
          console.log(parsed);
          // here I wish to forward the message to outside gmail addresses
        })
        .catch(err => {
          console.log(ee)
        });

    });
  }    
});

recvServer.listen(25);

recvServer.on('error', err => {
  console.log(err.message);
});

It works fine for receiving emails from outside, like gmail etc.

But I want to be able to send emails outside also, or forward emails that I receive to some gmail addresses.

I know that I can do that using Gmail SMTP servers, but then I need an gmail account and password.

I want to be able to send email with my own server, just like yahoo sends mail to gmail using their own server not gmail accounts :)

I have set up an email server on my host. It's basically a SMTP server that listens on port 25.

const recvServer = new SMTPServer({
  requireTLS: true,
  authOptional: true,
  logger: true,      
  onConnect(session, callback) {
    return callback();
  },

  onMailFrom(address, session, callback) {
    console.log('from', address, session);
    return callback();
  },    

  onData(stream, session, callback) {
    console.log('new msg');
    let message = '';
    stream.on('data', chunk => {
      message += chunk;
    });

    stream.on('end', () => {

      callback(null, 'Message queued');
      simpleParser(message)
        .then(parsed => {
          console.log(parsed);
          // here I wish to forward the message to outside gmail addresses
        })
        .catch(err => {
          console.log(ee)
        });

    });
  }    
});

recvServer.listen(25);

recvServer.on('error', err => {
  console.log(err.message);
});

It works fine for receiving emails from outside, like gmail etc.

But I want to be able to send emails outside also, or forward emails that I receive to some gmail addresses.

I know that I can do that using Gmail SMTP servers, but then I need an gmail account and password.

I want to be able to send email with my own server, just like yahoo sends mail to gmail using their own server not gmail accounts :)

Share Improve this question asked May 23, 2019 at 20:02 AlexAlex 67.7k185 gold badges459 silver badges650 bronze badges 3
  • 1 Note that if you want to send e-mails to a Gmail address, you need to authorize your server using SPF records, otherwise google will reject your e-mails. – Moritz Roessler Commented Jun 5, 2019 at 10:40
  • Postfix works fine. If you have your server hosted by a third party, you can usually use their SMTP servers as relay – Moritz Roessler Commented Jun 5, 2019 at 10:41
  • Alex - have you got your answer - if so please accept - if not please explain! – rivimey Commented Jun 7, 2019 at 10:57
Add a ment  | 

5 Answers 5

Reset to default 9 +200

You need a MTA (Mail Transfer Agent) in order to send an email.

So the popular options is: Postfix, here a guid how to setup postfix on ubuntu: https://help.ubuntu./munity/Postfix

Or you can spin up a docker container like: https://hub.docker./r/bytemark/smtp/

Then you can use nodemailer to send emails through postfix or docker instance.

And if you want there is a full stack docker image all batteries included: https://github./tomav/docker-mailserver

Technically you can use NodeMailer for sending emails.

"use strict";
const nodemailer = require("nodemailer");

// async..await is not allowed in global scope, must use a wrapper
async function main(){

  // Generate test SMTP service account from ethereal.email
  // Only needed if you don't have a real mail account for testing
  let testAccount = await nodemailer.createTestAccount();

  // create reusable transporter object using the default SMTP transport
  let transporter = nodemailer.createTransport({
    host: "smtp.ethereal.email",
    port: 587,
    secure: false, // true for 465, false for other ports
    auth: {
      user: testAccount.user, // generated ethereal user
      pass: testAccount.pass // generated ethereal password
    }
  });

  // send mail with defined transport object
  let info = await transporter.sendMail({
    from: '"Fred Foo 
发布评论

评论列表(0)

  1. 暂无评论