IBM Cloud Foundry firewall blocking SMTP connection (nodemailer) - ibm-cloud

My project uses Nodemailer to send service emails from the server. The code runs fine on my local environment, but when deployed to Cloud Foundry, it times out on the email sending connection.
Using SSH into the app container, curl google.com works, but curl --ssl smtp://smtp.email.uk-london-1.oci.oraclecloud.com doesn't work and times out.
Where and how could I configure this network access?
/sendEmail.ts
export async function sendEmail(toEmail): Promise<<SMTPTransport.SentMessageInfo> {
const transporter = nodemailer.createTransport({
host: ENDPOINTS.smtp.endpoint,
port: ENDPOINTS.smtp.port,
secure: false,
requireTLS: true,
auth: {
user: ENDPOINTS.smtp.credentials.id,
pass: ENDPOINTS.smtp.credentials.pass
}
});
return
await transporter.sendMail({
from: ...,
to: toEmail,
subject: ...
text: ...,
html: ...
})
}
const ENDPOINTS = {
smtp: {
endpoint: 'smtp.email.uk-london-1.oci.oraclecloud.com',
port: 25,
from: 'accounts-noreply#example.com',
credentials: {
id: ...,
pass: ...
}
}
}

The reason for not being able to use port 25 is because most of the cloud providers block access to it.
The reason for this is 25 is unauthenticated and often times abused by the SPAMers. Most the the email providers maintain Email Reputation System for known SPAM originating IP Addresses. So if you are a cloud providers you won't want to be the one that everyone blacklists.
TCP port 587 is used for authenticated SMTP access so its very less useful for SPAMers need to send spoofed mails.
Most the cloud providers will still allow you to send emails over 25 if you have a higher/enterprise subscription with them.
Useful Links:
Can I use outbound email on port 25? - IBM Cloud
Troubleshoot outbound SMTP connectivity problems in Azure
How do I remove the restriction on port 25 AWS
Outbound Internet E-mail(port 25) from OCI tenancies are blocked by default
How does blocking port 25 prevent spam

Try port 587 instead of port 25. Typically, port 25 is used by SMTP for unencrypted transfer, port 587 for SSL/TLS-based encrpyted transfer. Often, the port 25 is blocked because of frequent misuse.
For my projects, I usually don't even bother using port 25, but directly try 587.

Related

Setting up hMailServer to send and receive email

I'm trying to configure hMailServer on my computer to be able to send email out and also receive emails. I'm not sure if I have everything set up correctly as some tests works and some others do not so I am confused.
I have already set up in the DNS of my domain these 3 MX records:
mail.example.com
smtp.example.com
imap.example.com
Each one of those records points to the domain name of my server. I am able to connect to the web server of my domain. In my router, I have forwarded ports 25, 110, 143, 465 and 587 to my local computer running the hMailServer application. When running a port check on the web, it looks like port 25, 110 and 465 are blocked, but the rest are not.
If I open my Mozilla Thunderbird mail client, I set up an account I created in hMailServer for the domain in question.
I have also allowed the hMailServer application through my Windows firewall for both the private and public networks. I did the same for the Thunderbird email client.
I can locally send emails to myself and other local domains set up in hMailServer. However, I cannot send or receive any email to/from external recipients, like to/from Gmail or Hotmail for example. I'm getting this error message:
Error Type: SMTP
Connection to recipients server failed.
Error: Host name: 1.1.1.1 (edited) message: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Here are the TCP/IP ports summary in hMailServer:
The second part of my question is once I can actually send and receive email to/from external domains, how would I secure the connection (SSL/TSL...)? I already have a SSL certificate for my web server (example.com and www.example.com). Do I just need to generate another one for say mail.example.com or do email servers use a different kind of certificate?

Send Grid SMTP server sometimes can not connect

I am building a Jenkins server on my AWS EC2 instance. After building finish, I want to send email to stakeholder.
I am using STMP with smtp.sendgrid.net in port 587.
But I sometime can not send email. The log from jenkins says
MessagingException message: Could not connect to SMTP host:
smtp.sendgrid.net, port: 587
I access to EC2 instance and telnet to sendgrid. It says:
[hostname#domain ~]$ telnet smtp.sendgrid.net 587
Trying 161.202.148.179...
telnet: connect to address 161.202.148.179: Connection timed out
Trying 161.202.148.182...
telnet: connect to address 161.202.148.182: Connection timed out
Trying 169.38.103.39...
Connected to smtp.sendgrid.net.
Escape character is '^]'.
220 SG ESMTP service ready at ismtpd0004p1maa1.sendgrid.net
I understand that mean I can only access to some ip coming from smtp.sendgrid domain. I am sure to open all outbound rules for EC2. Because the problem happens sometimes, so anyone could give me any suggestion for this situaions.I intend to use IP instead of domain, but it just a workaround, IP can change anytime.
Please help me.
I had a similar issue, if your EC2 outbound rules are opened then you should ensure that you provide SMTP authentication along with your SMTP server and SMTP port and your DNS resolvers are good enough.
Sendgrid expects username and password.
username: it's "apikey", It might have to be encoded in base64 "YXBpa2V5".
password: it's your API Key, get it from Sendgrid and save it here. It might have to be encoded in base64.
I tried base64 encoded and it didn't work, so I tried without the encoding and it worked.
If your problem is not related to the authentication, you could review your DNS resolver, probably the problem would be there.

Google Compute Engine :Email solution

Google compute engine blocks outgoing smtp . The only option it gives in it's documentation is using sendgrid.
I have my own mailserver for transactional emails and other emails as well .
Can i Use another mail server ( not on google ) and create an smtp relay on compute engine ( on port other than 25 ) to forward port 25 traffic to that server ?
if so , how ?
See Googles documentation on this, I use SendGrid and Postfix to send email from my GCE instance.
By default, Google Compute Engine allows outbound connections on all ports but port 25, which is blocked because of the risk of abuse. All other ports are open, including ports 587 and 465.
You can use third party provider such as SendGrid, Mailgun, or Mailjet
For sendgrid: https://cloud.google.com/compute/docs/tutorials/sending-mail/using-sendgrid
For Mailgun: https://cloud.google.com/compute/docs/tutorials/sending-mail/using-mailgun
For Mailjet: https://cloud.google.com/compute/docs/tutorials/sending-mail/using-mailjet

Where to get the configuration? (Mail Client)

I just purchased a domain name few weeks ago,
and then i registered my domain into Windows Live Admin ( domain.live.com )
because from that Windows Live, I could manage
several email accounts. And I did. now every time I
want to write email / receive email i just go to mail.live.com
and login depend on the email accounts I just made there.
Then I tried to install Opera Mail, or even Thunderbird
in my Computer (laptop).
There are several configuration I confused.
What should I type into the incoming and outcoming server ? Imap / Pop? Which port?
I dunno....
Confused.
Because WHen I try to use thee details:
IMAP Server: as imap.charter.net SMPT Server: as smpt.charter.net
It doesnt work.
Then I tried to use
mail.mydomain.com
for both incoming & outgoing server.
And it is also doesnt work.
ANy ideas?
You have to use the outlook.com server, not your own domain:
Incoming mail server - imap-mail.outlook.com
Incoming mail server port - 993 (SSL)
Outgoing (SMTP) mail server - smtp-mail.outlook.com
Outgoing (SMTP) mail server port - 587 (SSL/TLS)
Outgoing server (SMTP) authentication - same settings as your incoming mail server

Symfony framework: How do I send email from localhost?

Using symfony framework how can I send test emails from localhost?
What are most easiest ways?
Thank you!
The easiest way, I suppose and what I normally do, is to configure the _dev environment to use good old Gmail (or any other provider for that matter). Set this up in your apps/frontend/config/factories.yml:
dev:
mailer:
class: sfMailer
param:
logging: %SF_LOGGING_ENABLED%
charset: %SF_CHARSET%
delivery_strategy: realtime
transport:
class: Swift_MailTransport
param:
host: smtp.gmail.com
port: 465
encryption: ssl
username: username#gmail.com
password: your-password
Sending e-mails will ofcourse take a little longer because PHP would have to connect to Google's servers and deliver the message.
This way you can worry about setting up a proper SMTP on your production server, and just let your dev machine be for development. Another advantage is if your develop on the road, and your local cafe / airport / kiosk blocks port 25 (they usually do) you won't have problems delivering mail.
You could install a mail server such as Postfix, and configure it to use an external mail server as an SMTP relay. Otherwise, most email services will either refuse to accept your message, or categorize it as spam.
This thread at serverfault might be helpful to you-it explains how to configure postfix to relay emails through gmail: Configure Postfix to send/relay emails Gmail (smtp.gmail.com) via port 587