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...

Access Control

Access control is about controlling user flow within your application. Do not mistaken access control with security which is a bigger subject in itself. Access control begins by authenticating user and limit his or her activity in your application. An activity is something like creating, updating or deleting a content. There are always finite number of activities that can be done in a given application. Each user can be assigned to a set of activities that he or she is allowed to do. Access control is usually tied to session management. However, you do not need session management to have access control. When a user log in, a session is created so that the user is remembered for the subsequent access. Otherwise the user has to keep on providing his or her credential for each access. We can also keep a list of activities that the user is allowed to do in the session record. Some applications let the session alive indefinitely and some applications time out user after a duration of inacti...

Separation of Front-end and Back-end Concerns

Separation of concerns is the cornerstone of MVC framework. Model, view and controller are three broad concerns of web-based software development. On its early days MVC was implemented on server side. The server renders views for clients. Nowadays, most clients render views themselves. Even the terminology of client-server has already morphed into front-end and back-end . The need for back-end to handle views is diminishing. View concerns have became increasingly complex with two big sub-concerns of aesthetic and dynamics. Front-end evolves into bigger MVC concerns of itself. While back-end evolves into larger modeling concerns. Now, front-end and back-end are two separate concerns. Front-end and back-end are handled by two different teams of software developers with different specialties. Back-end evolves into something like "dinner can be served even without plates, forks and spoons, without table and chairs, and without a dinning room." Front-end is serving the withouts....