configure 1and1 mail on google cloud platform with laravel 5 - php

I have setup an instance in google cloud platform. I am running laravel 5.2 project on that instance. Everything is working good but i am facing some issues while configuring 1and1 mail.
I know that google cloud platform is blocked the 587,465 and 25 port by default and we can setup some vpn which will help to remove this restriction. But i don't want to go in that way because it would have security problems.
I have tried to send email through smtp and mail driver. I am getting connection failure error through smtp driver, and through mail driver, it shows that email is sent but i am not getting the email in my inbox. Here is my .env file for mail driver settings for 1and1. I have also tried 25 port also.
MAIL_DRIVER=mail
MAIL_HOST=auth.smtp.1and1.co.uk
MAIL_PORT=587
MAIL_USERNAME=test#mydomain.com
MAIL_PASSWORD=pass
MAIL_ENCRYPTION=tls
Can you please help me to configure it?

As you alluded to, and documented, GCE doesn't allow outbound 25, 465 or 587. This is blocking your connection to 1and1.
If you can ask 1and1 to provide an alternate SMTP port (e.g. 2525 etc) then you can use that without issue.
Google also has partners that will allow you to send up to tens of thousands of emails monthly, for free. Pick one and follow the instructions here.

Related

Laravel sendmail driver

I'm having problems with the driver as it sends mail when I'm in my company, but once I come home with the same machine it doesn't do anything. Seems as it is storing it somewhere because when I get back to work I get all the mails I used to test when I was home.
My .env is set to a sendmail driver:
MAIL_DRIVER=sendmail
And I am sending a mail like this
Mail::to($data['user']['email'], $data['user']['name'])->send(new Confirmation($data['user']));
Everything seems to work when I'm at my workplace so I suppose there is some config file to set up which I don't know about that doesn't allow doing it from my IP?
Your ISP has probably blocked port 25 because of how easily (in the past) computers were infected and abused.
Instead, you should use encryption and port 465 which has been the defacto recommendation for awhile.

Sending emails using office 365 via php, connection refused (GoDaddy)

I'm at my wits end. We were having issues with sending email on a GoDaddy hosting, mostly that it was too unreliable (sometimes it worked flawlessly, sometimes I have to send several emails for one to go through, long queues, and so on. This is not the first time I've had these issues with them, by the way). So, I called them and their recommended solution was to set up an office 365 account and use that instead. I passed that information to my client, and he did it (albeit not via Godaddy's office 365 product, but directly with Microsoft, which certainly helps explain the difficulty), but I still cannot connect. I started to research this issue, but at this point I can say I am just lost. Here's everything I tried / learned, as well as the connections I'm trying.
My PHP setup is laravel 5.2, sending email via swiftmailer. The connection data is on an .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=myaccount#mydomain.onmicrosoft.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
And a sample php script sending emails
$logger = new \Swift_Plugins_Loggers_EchoLogger();
Mail::getSwiftMailer()->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger));
$master_email = "foo#bar.com";
Mail::send('emails.contact_us', $data, function ($message) use ($master_email, $request) {
$message->from("myaccount#mydomain.onmicrosoft.com");
$message->to($master_email)->subject('Subject');
});
And it fails with the message
++ Starting Swift_SmtpTransport
!! Connection could not be established with host smtp.office365.com [Connection refused #111] (code: 0)
There are plenty of comments saying that GoDaddy simply blocks outgoing smtp connections and forces you to use their relay service. However, all sources mentioning this seem to be outdated (2014 and earlier), not to mention I'm trying the setup that their support suggested on phone.
I've already did everything instructed on this microsoft article. On my office 365 admin account I can validate DNS to check if everything is okay, it says so. Microsoft support also says everything is correct. Domains are set up as "authoritative"
I've also tried setting up a connector and trying to connect to mydomain-com.mail.protection.outlook.com, fails with same error, so for now I've deleted that connector
I've called GoDaddy support to see if it was something like a firewall blocking my connection, and they said that's not it. They recommended deleting my workspace email account, I did so, still fails after that.
And so, I'm lost. I need this to work somehow, sending emails via microsoft's smtp server (and not godaddy's) specially because my client already set up his office 365 account and paid for it, so...yeah. Am I missing some configuration beyond the DNS changes? Should I connect to some other smtp server? Change hosts? Am I missing some parameter on my PHP scripts?
This seems to be fairly common issue, but it is surprisingly hard to find some definite answer. Hopefully my case will help others attempting something similar.
I had with the same problem in Laravel OctoberCMS on Godaddy.
The only config that worked for me is:
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=myaccount#mydomain.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
I hope this helps

Error connection mandrill (Laravel)

I have an issue with the mandrill API, I got this message :
Failed to connect to mandrillapp.com port 443: Connection timed out
It's works on my production server (ex mysite.com), but not on my dev server (ex mysite.com:8080).
The two servers have same config by the way.
Anyone knows why I got this issue ?
Thanks !
Make sure your hosting provider or internet provider (ISP) allows
outbound SMTP connections. Some shared hosting providers only allow
outbound SMTP connections on dedicated servers, while others block
them completely. In some cases, hosting providers might redirect the
connection, so instead of connecting to smtp.mandrillapp.com, you
connect to their local server instead.
Make sure the port you've selected is one that your hosting provider
or ISP has available for outbound SMTP connections. Some hosts block
all connections on port 25, for example, so you can try using a
different supported port.
Double check that you're using a valid API key to connect via SMTP,
and not the password that's used to log in to Mandrill's web
application.
If you're using Postfix, make sure that you have an SASL library
(like libsasl2 or cyrus) installed and that it's up to date.
Otherwise, you may be connecting but not passing authentication
credentials.
For other SMTP libraries, make sure you're using LOGIN or PLAIN
authentication methods.
Once you've confirmed all of the above, if you're still seeing issues,
please enable additional logging in your SMTP program or library. If
you're using an integration, contact the integration developer for
information on configuring logging of the SMTP conversation.
Where do I find my SMTP credentials?
After you create a Mandrill account, get your SMTP credentials on the
SMTP & API Info page in your account.
The SMTP password is any active API key for your account, not the
password used to log in to Mandrill. The credentials list port 587,
but any port supported by Mandrill will work, and there's no
configuration change needed within Mandrill to activate one of the
alternate ports.
Which SMTP ports can I use?
You can use port 25, 587, or 2525 if you're not encrypting the
communication between your system and Mandrill or if you want to use
the STARTTLS extension (also known as TLS encryption). SSL is
supported on port 465.
ISPs may redirect traffic on certain ports, so it's up to you which
port you use.

Gmail SMTP is not working in ec2 instance

i am using Ubuntu based ec2 instance, recently i have shifted my code on aws and it seemed email functionality is not working. I am using gmail SMTP service
below is my code
'Smtpmail'=>array(
'class'=>'application.extensions.smtpmail.PHPMailer',
'Host'=>"smtp.gmail.com",
'Username'=>'username',
'Password'=>'password',
'From'=>'from addr',
'setForm'=>'from name',
'Mailer'=>'smtp',
'SMTPSecure'=>'tls',
'Port'=>25,
'SMTPAuth'=>true,
),
this code is working on my unix based server but on aws it is giving below error
Mailer Error: The following From address failed: test#email.com : MAIL not accepted from server,530,5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 y6sm27370508qen.21 - gsmtp
Please help
MAIL not accepted from server
Because of the spam abuse that has historically been sent from people using EC2 instances, virtually ALL popular mail providers block the receipt of email from EC2 instances. The world of email and anti-spam measures is part-technical, part-political. For this reason, AWS offers Amazon Simple Email Service.
AWS works with mail providers to ensure that the nodes used by SES have been whitelisted because we do proper authorization/verification up-front.
In this case, the ability to send email from one server but not AWS is, in all likelihood, due to EC2's IP range being blacklisted by Google.
Authentication Required
If the same user/pass works elsewhere without changes, I'm not sure what to say. I know that lots and lots of mail traffic no longer uses port 25, opting instead for 587 for non-SSL and 465 for SSL. That's the first place I'd start poking to find a solution.
Using a TLS connection (port number: 587) on AWS Lambda.
How I solved the problem:
In your GMAIL account, turn on 2-factor authentication. This can be found under security settings when you go to general settings for your account.
Create a new App Password. (The field is right below the 2-factor). You can call it whatever you want. Just make sure to copy it.
Use that for your previous password.
I did that and I can send emails from AWS Lambda with no problem.
Note: You can't have "Less Secure Apps" turned on for this option. This will require you to use the App password for every application you use this email for. I had to make a few different passwords for the different apps that I use a random Gmail account for.
I got the idea from SMTP Authentication Error 534.
This has nothing to do with your ec2 instance (unless the relevant outbound ports are closed) but with the fact that Gmail really doesn't like a connection it can't identify. As stated in the thread, make sure you go to https://www.google.com/settings/security/lesssecureapps.
Then, once your instance tries to connect to the SMTP server (by sending an email in your web app I suppose), connect to your mail client with the gmail account credentials used for the SMTP connection (Gmail, thunderbird, whatever you normally use). You will have then received an email from google stating that there was some suspicious activity and that they blocked the connection, just tell them that the ec2 instance IP was indeed you and you will be all set.
I was using a Gsuite account. For me, it worked with the following steps
Make sure you have 2 step verification enabled
Generate App password from myaccount.google.com -> security (from left panel) -> 2-step verification (under "signing in to google" section)
Once 2 step verification is enabled then generate the app password.
Use that app password in your config/mail.php on .env along with the following settings
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=tls
Open the terminal/ command prompt and connect to the EC2 server and run the following commands to clear config and cache
php artisan config:cache
php artisan cache:clear
If that still does not work then click on the following link (Make sure you are logged in with the account which you want to use to send email via Gsuite)
https://accounts.google.com/DisplayUnlockCaptcha
This only need to verify gmail account when u login from another ip address it will ask for verification that you are the same person same thing happen here it is not verified from amazon web server IP so it require to authenticate your IP.
Do only one thing will solve the issue. Login remotely on aws server and login your gmail account from here it will ask for verification give it and your mail will work easily.
If you use port 25 for SMTP you need to open SMTP port on EC2 instance security group inbound rules.
Note: Gmail does not offer port 25 in an unsecured connection. For use port 25 secure connection are required as per gmail Configuration requirements
Read this question & answer
How do I use Gmail SMTP with port 587 on AWS EC2?
Go to https://www.google.com/settings/security/lesssecureapps and set Access for less secure apps to On
This gmail security option if on Off detects if there is inhabitual connexion pattern and block the connexion unless you verify your identity, but you need a web interface to do so.
Log into your AWS account, add rule under security group of your instance and allow the SMTP, it will work, check the port number is important.

Need Configuration Settings

I have developed flex based application with php. My client is using Windows 2003 Server. I installed IIS Server and Php Installer into my client machine. I configured php into IIS Server and its working fine.
Query:
I wrote a mail code for sending mail to my application user. My client is using internal mail server. I want to send a mail through my application. I used smtp.gmail.com into my application and Its working perfectly. But when I am using client internal mail server. It is showing below mentioned error.
"Failed to set sender [SMTP: Invalid response code received from server. (Code: 554, response: Mail from mail-id rejected for policy reasons.]"
Please help me out to solve this query. Thanks in advance.
Well, why not to ask client's system administrator about "policy reasons"?
This should be no PHP problem but rather a problem with the SMTP server or a misconfiguration of the SMTP settings in your application. SMTP servers can be equipped with a lot of security features (I think that's what they mean with policy reasons) to allow or deny sending emails through that server from specific hosts, from specific uses, with specific authentication mechanisms, to specific domains, to specific users, etc. (list can be continued endlessly). Contact the responsible system administrator for that SMTP server and ask him what settings you need to feed into your SMTP mailer in your application.

Categories