Miksus/red-mail

Different sending email address or alias when sending via gmail

LucSpan opened this issue · 5 comments

Is your feature request related to a problem? Please describe.
No.

Describe the solution you'd like
Allow for different sending email address or alias when sending via gmail – i.e. from redmail import gmail.

Describe alternatives you've considered
None.

Additional context
n/a

Actually it seems it's possible for current version of Red Mail, for example:

from redmail import gmail

gmail.user_name = 'example@gmail.com'
gmail.password = '...'

gmail.send(
    subject='An example',
    sender='MyName <example@gmail.com>',
    receivers=[...],
)

The sender should show as MyName and at least worked for me. I'm not sure whether Gmail supports using different email addresses as the sender, at least haven't when I tested it but not entirely sure either. If you have your own SMTP server, you should be able to change the sender (if the server allows it).

However, I'll leave this issue open as I think this could be at least documented.

Hi Miskus, thanks works for me too!

I've got multiple email addresses linked to my Workspace and I believe gmail allows for different sender addresses.

Have you managed to try whether it works by just changing the sender in calling EmailSender(...).send?

I also found Google's instructions for sending from a different address. I could try that one day whether I could make it work with Red Mail also. My assumption is that this possibly might not require code changes but I'll see what it requires when I have time.

Not sure what you mean, but

  gmail.send(
      subject='An example',
      sender='MyAlias <example@gmail.com>',
      receivers=[...],
  )

shows MyAlias as the sender, the sender email address will still be example@gmail.com.

If you know how to use another email address as the sender, I'd be happy to know!

I mean just changing the sender argument to the other address you have. Normally Gmail does not allow that, probably to prevent impersonating other users, but if you have linked the accounts I think it might work that you just change the sender to the other address.

Red Mail is able to send emails using a different address as the sender if the email server allows it. For example, at work I can send emails like:

email.send(
    subject="An example",
    sender="no-reply@company.com",
    receivers=[...]
)

If I set the email to connect our SMTP server and our company had the domain company.com. I think the limitation is just whether your email provider allows changing the sender or not, and for Gmail that's typically not possible. But if you have linked the emails, I don't know whether then Gmail allows to do something like this:

gmail.user_name = "me@gmail.com"
gmail.password = "..."
gmail.send(
    subject="An example",
    sender="my_another_account@gmail.com",
    receivers=[...]
)

The link I provided shows how to change the from address to another account you have but I'm not sure whether Gmail allows this when sending emails using app password (sending using Red Mail). That needs some testing.