Skip to main content

Sending SMTP Email via Telnet

You want your webhost to be able to send emails through an external SMTP server. The first thing to do is to check whether your webhost provider allows this to happen. Some concerned providers block outgoing SMTP ports to prevent you from doing email spamming. Let's try to connect with the SMTP server via Telnet from within your webhost. You may need to SSH into your webhost first. And then issue the following command:

$ telnet -4 mail.example.com 587

The above command will connect to the mail.example.com SMTP server via port 587 and force Telnet to use IPv4. If the connection fails then your webhost provider may have blocked the outgoing SMTP port 587. You may need to politely ask your webhost provider to open the port for you. You can't do it yourself.

Note: Telnet will resolve to IPv6 by default. If the SMTP port is not open on IPv6 then Telnet will appear hung until all trials via IPv6 connections are timed out. If IPv6 failed then it will resolve to IPv4. 

Telnet should have received a response like the following:

Trying xxx.xxx.xxx.xxx...
Connected to smtp.server.com.
Escape character is '^]'.
220 smtp.server.com ESMTP Exim 4.95 Thu, 30 Jun 2022 20:33:24 +0000

Say hello to the SMTP server. You must do this before sending an email:
ehlo mail.example.com

It will respond like the following:
250-smtp.server.com Hello mail.example.com [xxx.xxx.xxx.xxx]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-PIPE_CONNECT
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP

Then you need to login using an email credential with the SMTP server:
auth login

It will ask for an email username:
334 VXNlcm5hbWU6

VXNlcm5hbWU6 is a base64 encoded string which will decode to Username:

Enter the based64 encoded username (i.e username as in username@example.com without the @example.com).

Then it will ask for the email password:
334 UGFzc3dvcmQ6

UGFzc3dvcmQ6 is a base64 encoded string which will decode to Password:

Enter the based64 encoded password.

It will respond with:
235 Authentication succeeded

Start composing an email by issueing the data command. No need to encode the content in based64. Then send out the email by ending the composition with a single dot (.) command on the last line:
data
354 Enter message, ending with "." on a line by itself
from: Admin <admin@example.com>
to: someone@gmail.com
Subject: Greetings from Webhost via Telnet

Hi!
This is a RFC 5322 compliant email sent using telnet from a webhost.
.
250 OK id=1o71wm-0006hR-UR

The '250 OK' response means that your email was accepted, but not necessarily delivered to the destination. 

A RFC 5322 compliant email must have the from: email address. Gmail will not accept an email without the from: email address.

Now you can end the Telnet session:
quit

Verify that the email reaches its destination. But that is beyond Telnet. If the email is stuck somewhere then you need to consult with the SMTP service provider. This test is only to prove that your webhost has a clear communication channel with the SMTP server. Next, you may want to setup mail service in your webhost so that webapps can send emails. 



Comments

Popular posts from this blog

Setting Up PyScripter for Quantum GIS

PyScripter is a general purpose Python Integrated Development Environment (IDE). Quantum GIS (QGIS) is a desktop GIS application that can be extended with Python plugins. Both are open source softwares. We intend to use PyScripter as an IDE to build QGIS Python plugin. We are using PyScripter 2.4.1.0 and QGIS 1.6.0 in Windows. PyScripter does not come with Python. On the other hand, QGIS is built in with Python. Thus, we will setup up PyScripter to use the build in Python in QGIS. We assume both PyScripter and QGIS are already installed. Preparing PyScripter batch file We assume that QGIS is installed in C:\OSGeo4W\ folder and PyScripter is installed in C:\Program Files\PyScripter\ . 1. Copy qgis.bat in C:\OSGeo4W\ bin to pyscripter.bat 2. Edit pyscripter.bat to remove the last line that read something like this start "Quantum GIS" /B "%OSGEO4W_ROOT%"\apps\qgis\bin\qgis.exe %* and replace it with this in one line Start "PyScripter" /B "C:\Progr

Sending Emails via SMTP

msmtp  requires a minimal setup for sending emails via SMTP compared to sendmail. Here is a configuration for you to send emails from a web host to an external SMTP server. Prior to doing that, you must check whether there is a clear communication channel between your web host and the SMTP server. You can use Telnet . Set up msmtp You are going to set msmtp as an MTA . Hence, you need to remove all other MTAs such as postfix and sendmail: $ sudo apt-get --purge autoremove postfix sendmail Install msmtp and related utilities: $ sudo apt-get install msmtp msmtp-mta mailutils Configure msmtp: $ sudo nano /etc/msmtprc # Set default values for all following accounts. defaults # Use the mail submission port 587 instead of the SMTP port 25. port 587 # Always use TLS. tls on # Set a list of trusted CAs for TLS. The default is to use system settings, but # you can select your own file. tls_trust_file /etc/ssl/certs/ca-certificates.crt # The SMTP server account mx host mail.mx.example

fatal: Couldn't find remote ref master

If you are using Github then  master is now known as main . Whatever you want to do with a master must now be referred to a main . If you search for this error message on the Internet then you will encounter with a lot of old discussions on how to set up your master properly which is probably not what you are looking for. The master  is your problem. Rename it to main . I wrote Git My Way about two years ago. Today I created another Github repository. I got this  "fatal: Couldn't find remote ref master"  error message when I wanted to sync the new repo for the first time with my notebook using the notes I wrote in the blog. All the discussions around the error message I found on the Internet were perplexing. Then I recalled that Github had renamed master to main  due to the master-slave connotation. We always have a master copy of a code, never a slave copy. Now suddenly a word context has been diminished for good. What is going to happen to the existing vast documen