Send emails from GCP compute instance using smtp-relay of GMAIL - smtp

I am trying to send mail from a compute instance using Gmail's smptp relay and I have enabled smtp-relay through my GSuite account and have also configured POSTFIX in my compute instance and as per mail.log file the mail has been delivered but it is not appearing in my Gmail box. Could you please let me know what is being missed?
Here is the log for the same.

At first, have a look at the Firewall rules overview where at section Always blocked traffic you can find that:
Google Cloud always blocks the traffic that is described in the
following table. Your firewall rules cannot be used to allow any of
this traffic:
So, you should follow documentation Choosing an email service to use:
To use a G Suite domain: Follow the instructions for SMTP relay
service settings in the G Suite documentation. SMTP relaying through G
Suite is only allowed through ports 465 or 587.Port 25 is not
supported through G Suite.
and use ports 465 or 587 to connect to G Suite.
Also have a look at this guide SMTP relay: Route outgoing non-Gmail messages through Google:
In the Allowed senders section, select the users who are allowed to
send messages through the SMTP relay service:
Only registered Apps users in my domain—The sender must be a registered user in one of your domains.
Only addresses in my domains—The sender doesn't have to be a recognized G Suite user, but must be in one of your registered
domains. This can be useful when you have third-party or custom
applications that need to send messages.
Any addresses (not recommended)—The sender address can be anything, even an address outside of your domain.
Important: The Any addresses option makes you more vulnerable to abuse,
either through malware on your user’s machines or by
misconfiguration of your SMTP infrastructure. Therefore, we don't
recommend this option.
and check who is allowed to send emails, then follow next step:
In the Authentication section, check one or both boxes to set an authentication method:
Only accept mail from the specified IP addresses—The system only accepts mail sent from these IP addresses as coming from your domains.
Require SMTP Authentication—Enforces the use of SMTP authentication to identify the sending domain. Using this option
requires your clients to connect via TLS.
and check if you use whitelisted your instances.
In addition, this example could be useful to check your steps.
In case if you still have an issue, check possible alternatives SendGrid:
This tutorial shows how to use SendGrid to send email from an app
running on a Compute Engine instance. SendGrid is a third-party email
service that offers Compute Engine users a free trial with 12,000
transactional emails free each month.
or Mailgun, or Mailjet. If they work for you, but you still need G Suite you can contact G Suite Support. It they don't work for you also - you should check you Postfix configuration first.

Related

Cannot send email using SMTP server through Office 365 with ADFS

I am trying to send an email using the smtp.office365.com server. It always return the same error:
5.7.57 Client not authenticated to send mail.
As far as I know, the problem is related with the fact that I'm working with ADFS. So I have previously federated my domain to work with Office 365. When I try to log in to Office, I'm redirected to the login page of my platform, which is fine.
Is there a way to send email using the Office smtp server when working with ADFS?
Not to my knowledge, you need to change the primary username to use your tenant domain rather than your federated domain. Then you'll be able to log in without ADFS.
We configured a single account for SMTP with just an Exchange Plan 1 license, and then set up internal SMTP relays using that account to transmit to O365. We then limit connections on that account to only known locations. Then we add SendAs permissions for that account to all the DLs/mailboxes that we need to send email from.

Unable to send mails with SMTP in GCE instances

While migrating from AWS EC2 instances to Google Compute Engine instances we got problems with sending emails via SMTP (Sendgrid).
I read a lot about it and read that the ports (587, 462, 25) of SMTP are blocked... And to read this article.
https://cloud.google.com/compute/docs/tutorials/sending-mail/#sending_mail_through_corporate_mail_servers
Questions:
For my understanding we should open a Cloud Launcher of SendGrid?
If (1) = yes, then I see it (the cloud launcher) does not support C# and our code today of sending emails is based on C#. So that we will have to change the code to one of those: Node.js, Python, Ruby, Go & PHP?
Is there any way to unblock this outbound connections on port 587 (or 462, 25)? Without Cloud Launcher.
Thanks in advance
1) Yes, if you want to use it through google. If not I recommend directly going to one of the smtp providers such as sendgrid, spakpost, mandrill... to get and account and use their smtp service to send mail.
2) You can use C# by simply not using the Cloud Launcher and purchasing an account directly from the vendor and usning their SMTP service.
3) No, port 2525 is free to send outbound emails to smtp providers through GCP so I highly recommend using that since it can be used for sendgrid as well.

Google Compute Engine (GCE) email delivery solution?

I've just setup several instances on Google Compute Engine and getting trouble with email delivery system since GCE blocks outbound connections on ports 25, 465, and 587.
GCE provides details solution at: https://developers.google.com/compute/docs/networking#mailserver to using postfix to send email via smtp.gmail.com using Google Account.
The problem is Gmail has its own sending limits and it will be a big problem for high traffic website which need to send email notifications heavily.
Is there anyone has a solution to send more higher sending limits for GCE instances?
Thanks in advance.
Best Regards,
T
From the same page:
Blocked Traffic
Traffic on these ports to and from the Internet are blocked or
restricted for all Google Compute Engine instances. If you think you
have a compelling reason to allow this traffic, please contact the
Google Compute Engine team at gc-team#google.com.
All outgoing traffic to port 25 (SMTP) is blocked
Most outgoing traffic to port 465 or 587 (SMTP over SSL) is blocked except
for known Google IP addresses
https://developers.google.com/compute/docs/networking#blockedtraffic
It looks like you'll need to have a compelling reason to allow the traffic for your application; I'm presuming that hitting GMail delivery limits might be a reason. Note that companies like SendGrid also offer email delivery and management (bulk email as a service) with an HTTP interface that you could call from GCE.
We've updated our documentation to include SendGrid as an additional option. You probably want to take another look.
https://developers.google.com/compute/docs/sending-mail?hl=en
Your best option is to sign up for Amazon SES and get the API credentials and endpoint to send mail from google cloud without any google limitations.
You can use any similar API as well.

Using host's native SMTP to send emails alongside Google Apps

Current Setup
I use Google Apps for personal / non-transactional emails. MX records for my domain point to google.
I have a dedicated IP for my LAMP server, and the SMTP port is available. I use cPanel to manage the server. I have created an email account through cPanel.
Goal
I want to use my host's native SMTP for sending transactional emails. I cannot use Google Apps SMTP because of per-day limit. These transactional emails need neither be saved in sent items nor replies to such emails be monitored.
Problem Area
I am not able to send transactional mails using host's native SMTP (not able to set this up, so no errors yet!)
Q1. Is the goal (using both host's native SMTP and Google Apps)
achievable? Looking at this and this, I believe it should be.
Q2. If yes, how should I setup in my cPanel? Please let me know if more [relevant] information about server setup is required to answer this.
Q1: Yes.
Q2: Same as if you were setting it up without Google Apps. Sending mail does not require any special setup. If you are still having difficulty, you need to check with your provider or ask the question of a cpanel expert -- the problem is unrelated to Google Apps.
What you didn't ask but need to know:
Cannot deliver email to Google Apps address; Gmail receives the same email fine
Why can't my server send outgoing email?

Need help setup windows server 2008 SMTP server

I am trying to setup windows server 2008 smtp server to relay emails to gmail smtp. Everything appears to be setup but it is not sending emails. Could you please help me figure out whats wrong.
Below is the setup:
Windows server 2008 with SMTP server
feature installed. Need SMTP server
to forward all messages to gmail smtp
server to send.
I have google apps setup for my
domain, also I can send emails
throught my test app using
gmail smtp.
SMTP Server Configuration: By default has default smtp server virtual directory.
In Properties of that virtual smtp server changed following.
Fully qualified domain name = mydomain.com
smart host = smtp.gmail.com
TCP Port = 587
Out Bound Security = Basic Authentication(my username password for google apps email account)
In domains list under virtual smtp server. I have one default domain that's server dns. I added another one for my domain name.
With above setup i am trying to redirect all email to gmail smtp.
I tested connection to smtp.gmail.com from server on port 587 through telnet and it works.
I am trying to use above server from my web application also by just dropping emails in pickup directory. It get's picked up and also accepts request form web application but never sends an email.
I can see that it adds those emails in queue folder but it stays there forever.
When i try to send emails from web app to above server it rejects if To address is other than my domain.(Am i missing something in list of domains)
Thanks for all answers, finally found solution there is a property for maximum sessions which value was 0 by default. Changed it to 100 and it send all pending emails immediately.
Possible reasons are that some SMTP servers block the outgoing messages if there domain name mismatch, possible to prevent spam mails from being sent. So for example, I will not be able to send my email with an address abc#mydomain.com from my domain yourdomain.com.
Hope that helps.
Ensure your sending domain is the same as the google apps domain
Ensure your sending address is a real address and not just an alias
IIRC you need to use STARTTLS (SSL) not basic authentication
This souds like a DNS issue. Check your /badmail directory. It will have .bad and .bdp files in there. You can open these in notepad (there will be some binary in there).
However, it may point to the possible problem.
You may also want to try and enable logging on the SMTP service. There may be something in there.