PHPMailer using GMAIL SMTP with multiple GMAIL accounts for multiple virtual hosts - apache

I have already set up PHPMailer and it already worked with one domain,
using a gmail account for the SMTP service.
When I wanted to use PHPMailer, likewise, with a different
Gmail account (for a different virtual host),
it would still send it from the same Gmail acccount
because that's what is identified as "the email address" of the server
(of the server on which severe virtual hosts run)
my question is, what do you need to have in order to be able to be able to use
another Gmail account?
another IP address? or another server? or?
and what will be the ultimate limitations in terms of the FROM ADDRESS
if you only have one IP address and one server?
thank you

Gmail does not mind you using multiple accounts from the same IP, so long as you authenticate correctly for each. That is, there is no fixed relationship between the server you're sending from and the gmail account you use.
The one thing that will be the same across accounts is the EHLO hostname (set via PHPMailer's Helo property, if it can't be derived automatically), because you really want that to resolve backwards as well as forwards in DNS, and you can't do that with multiple names at once - but that has no effect on authentication.
There's no need for the actual hostname of the server to be related to the domain you're sending from, so you can safely say:
$mail->From = 'user#vhost1.example.com';
$mail->Username = 'user#gmail.com';
and then, in another vhost:
$mail->From = 'user#vhost2.example.com';
$mail->Username = 'user2#gmail.com';
If you watch the SMTP conversation (SMTPDebug = 2), both will have the same EHLO name (which might be a generic host.example.com), but then use different authentication and MAIL FROM addresses (the SMTP source address, which may be different from what's in the message's from header if you make use of the Sender property, but either way it will be turned into a return-path header by the receiver) for sending the messages.

Related

iRedMail messages missing DKIM header

I setup a clean iRedMail installation on a new server.
I followed the instructions here:
https://docs.iredmail.org/install.iredmail.on.debian.ubuntu.html
and then setup the dns records like so:
https://docs.iredmail.org/setup.dns.html
I also added a certbot certificate: https://docs.iredmail.org/letsencrypt.html
I can now receive email from all other email providers and can send email to other users of my domain. But I cannot send email to other email providers, it doesn't even end up in the spam folder.
After some research i found out that my emails are missing a dkim signature which is the most likely reason they aren't picked up by other servers.
I did the amavisd-new testkeys test and passed, although I'm pretty sure it doesn't work, since it also works if I don't setup any DNS records.
So my questions are:
shouldn't my emails be DKIM signed for some reason?
which service is responsible for adding DKIM headers to emails?
Where can I find out why it doesn't sign my mails?
Turns out Amazon blocks outgoing traffic on port 15 by default. Took me a while to figure out. There was no problem with DKIM.

Issue With Receiving Keycloak Email to the Clients

I have a fully functional Keycloak setup with verify email and then update password features enabled. I have tested multiple times and the mail sending part is working perfectly. But some clients reporting that they didn't receive the registration mail. This maybe due to their firewall, spam filter and so on, now I want way to check whether the email has sent from my system or not. Logs won't help at all, cannot find anything related to sent mails in logs.

Sending email with Javamail from a script without a password

I have a script that runs a Java program to run some tests every night. It needs to email out the results of the tests, using JavaMail and a Google apps account.
How do I authenticate with Gmail (through the JavaMail API), without storing the password on the machine that runs the nightly tests? Can I get some sort of an Gmail authentication key that is valid for, say, a month? I don't mind refreshing the key every month, but don't want to keep the password on the test machine.
Google email accounts cost money so I would prefer not to create a new account just to email test results out.
I haven't tried that myself but you can try to send in the mail using the MX servers of googlemail. Currently these are
~ $ host -t MX googlemail.com
googlemail.com mail is handled by 40 alt4.gmail-smtp-in.l.google.com.
googlemail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.
googlemail.com mail is handled by 20 alt2.gmail-smtp-in.l.google.com.
googlemail.com mail is handled by 5 gmail-smtp-in.l.google.com.
googlemail.com mail is handled by 30 alt3.gmail-smtp-in.l.google.com.
These are the servers responsible for inbound mails from the outside world, it's plain SMTP without the need of authentication (but you can try to start TLS to make the transfer more secure). There might be checks though, that prevent you from delivering mails to these servers (dyn-IP-checks, SFP, etc.) which is why this might fail.
If you don't want to send to a Google mail address you can try the same thing but replace the MX server of Google with the one responsible for the mail address you want to send to. Just use above call with the different domain or use one of the search results for "mx lookup" if you don't have that as command on your system.

How to send mail via smtp using ssl in php

How can I send mail via smtp using ssl? We are able to send the simple text mail, but it's not allowing the links or certain tags in the mail to pass, we tried using pear-mail.
Please suggest any options.
We are using third party GMAIL and hosting is in Godaddy. All mx record are fine and earlier we were able to deviver mails when we have not used ssl, also as i mentioned we are able to send the simple text mails with ssl, so please no answers regarding hostings, just any options how to use it with ssl.
You might want to look at phpmailer. You can use phpmailer to send outgoing messages through gmail's SMTP server (smtp.gmail.com), and it has options to connect to the SMTP server by SSL. phpmailer is very simple to setup - just a few PHP files to copy to your server. See https://github.com/PHPMailer/PHPMailer. You can start sending mail using the simple example at the github page above as a boilerplate.

Get SMTP automatically

I am using code to send email through SMTP that is given manually. I wish that user does not have to give the SMTP. My application should get SMTP automatically and use that.
Can I know what is the SMTP of the current ISP, with which my client is connected?
Thanks
Furqan
You could try to read that from the user's e-mail clients; AFAIK each e-mail client (e.g. Outlook, Thunderbird, Opera, Eudora) stores the SMTP server settings differently; so probably look for the most common ones (Thunderbird, Outlook, ?). Also, some people only use web-based e-mail (esp. gMail users), so they may not even have a SMTP setting stored anywhere.
Note: nosing around in other apps' settings can be seen as borderline spyware, so I suggest to get permission from the user before you start digging in their app settings.
No, I don't think this is possible. What you could try is to look if the SMTP server is configured in an other program. E.g. under Windows in Windows Mail. However, I don't know if it's worth the trouble. Today SMTP auth is common and probably no other program gives you access to the users credentials so you have to ask the user in all cases.