FLYNNLABAboutMeCodingActivityStudy 2024초등수학
Meteor Email
meteor, email

meteor email

Server 에서만 사용가능 smtp를 이용하여 email을 보낼 수 있다.

meteor add email

settings

gmail stmp

// server/smtp.js
Meteor.startup(function() {
  var smtp = {
    username: 'senduser@gmail.com',
    password: 'password',
    server: 'smtp.gmail.com',
    port: 465
  };

  process.env.MAIL_URL = 'smtp://' + smtp.username + ':' + smtp.password + '@' + smtp.server + ':' + smtp.port;
});

Meteor.methods({
  sendEmail: function(sendAttributes) {
    check(sendAttributes, {
      to: String,
      from: String,
      subject: String,
      text: String
    });
    // 호출 순서 무시 하도록 설정 > 성능상 이점
    this.unblock();
    // 메일 보내는 사람의 권한 확인
    if(!Roles.userIsInRole(this.userId, 'admin')) {
      throw new Meteor.Error('not-authorized', '어드민 사용자만 메일을 보낼 수 있습니다.');
    }
    Email.send(sendAttributes);
  }
});

다른 주소로 보내기

gmail > 환경설정 > 계정 및 가져오기 > 다른 주소에서 메일 보내기 설정