meteor / meteor-feature-requests

A tracker for Meteor issues that are requests for new functionality, not bugs.
Other
89 stars 3 forks source link

Support for multiple sender emails #409

Open diavrank opened 3 years ago

diavrank commented 3 years ago

Before opening a new feature request, please note:

The problem:

Currently, if you want to send emails from a meteor app you can do it only with a sender email, which is configured in the MAIL_URL environment variable. So, I think if you have a small app that is enough but if you are going to build enterprise applications, it is very common to send emails from different senders such as promotions@yourcompany.com, support@yourcompany.com, sales@yourcompany.com, etc. So, yo can't do that with the package of Email Meteor.

Suggested solution:

I was researching and I found out that you have to use third dependencies such as nodemailer or ostrio:mailer, but I think that this feature should be in Email Meteor because I noticed that this package uses nodemailer, so, I think it shouldn't be a lot of work to take that feature of nodemailer into the Email package.

StorytellerCZ commented 3 years ago

I have started to move the email package to make this a bit easier. First step is making the send email hook public so that you can intercept emails being send out and based on that change their properties or you can stop them being send out completely and instead use your own api. That is also a common practice that for stuff that is not Meteor sending out email you use the API of the service you use.

diavrank commented 3 years ago

Thank you. Also, I want to share you how I was imagining the usage of that part:

At the beginning of your file (for example MailServ.js) of email configuration put the following:

Email.config({//By default, the sender email will be established from **MAIL_URL**.
transports:[
{
    sender: "sales",
    host: "smtp.gmail.com",
    port: 587,
    secure: false, // true for 465, false for other ports
    auth: {
      user: "sales@yourcompany.com", 
      pass: "password",
    },
  },
....//more senders if you want
]
});

Once you have configured the email configuration, you can send emails as follow:

Email.send({
   sender:"sales",//this option is optional. By default, takes the default sender defined from MAIL_URL.
   to:"",
   from:"",
   subject:"",
   ...
});

This will be great on Meteor 2 :) .

I don't know if this can be possible or is difficult to implement it, but I think that is a simple way to use it.

References: https://nodemailer.com/about/


On the other hand, I found out how to do it with G-Suite (gmail enterprise service). I had to configure some "aliases" for the email sender. These "aliases" are emails used for departments (sales, support, marketing, etc) in a company. So, I used a sender email as master (this is configured in the MAIL_URL environment variable) and for each Email.send({from}) I used the aliases and it worked!!!. However, I don't know if this is possible for other email providers (such as mailgun, microsoft outlook, etc). so, I still see it convenient to implement that feature for email package. Later, I will publish a post (on forum) to share this solution

StorytellerCZ commented 3 years ago

@diavrank I will consider this for the next major version of the email package.