The SMTP (Simple Mail Transfer Protocol) is an Internet standard for electronic mail (Email) transmission across Internet Protocol (IP) networks.
This tutorial shows how to connect to SMTP mail server and send an Email using the ‘telnet’ command.
Step 1: Open a connection from your computer to an SMTP mail server
$ telnet smtp.domain.ext 25 220 smtp.domain.ext ESMTP Sendmail ?version-number?; ?date+time+gmtoffset?
- smtp.domain.ext – Your mail server;
- 25 – Default port for SMTP.
Step 2: Declare your domain name or IP-address
You can set local.domain.name or anything you want in ‘HELO’, because the server doesn’t check its authenticity, that is one of the drawbacks of this protocol.
> HELO local.domain.name 250 smtp.domain.ext Hello local.domain.name [xxx.xxx.xxx.xxx], pleased to meet you
Step 3: Set sender’s email
> MAIL FROM: sender@adress.ext 250 2.1.0 sender@adress.ext... Sender ok
Step 4: Set recipient’s email
> RCPT TO: recipient@adress.ext 250 2.1.5 recipient@adress.ext... Recipient ok
Step 5: To write the message, type DATA and press ‘Enter’
> DATA 354 Enter mail, end with "." on a line by itself
Step 6: On the first line type ‘SUBJECT: Your Subject’ and press ‘Enter’ twice
> SUBJECT: Test message
Step 7: Continue typing your message
Hello, this is a TEST message, please don't reply. Thank you.
Step 8: Put a single period (.) on a line by itself and press ‘Enter’ to send your message.
> . 250 2.0.0 ???????? Message accepted for delivery
Step 9: Close the connection
> QUIT 221 2.0.0 server.com closing connection
How can I automate this? I want check some condition if condition met I want to send mail If condition not met skip sending mail
use an arduino or similar micro-controller. you can get ethernet daughter boards, or some of them have WIFI chips/ethernet built in. you will have to hard code the above in to a function in arduino ide, and build in a way to view/handle the response codes. there was a good tutorial on this on youtube by a guy named ralph bacon. use the i/o pins on the micro-controller to trigger your function and send the email. make sure you have protections built in so you don’t spam. OR if you want to do this all from a pc then write a script. maybe powershell ide would be good for this. i used it for a small project because the documentation was pretty good and the ide and everything was pre-installed on my desktop at work already. good luck
OR just use perl/python to carry out the interaction.
Thanks for putting this up. Greatly useful to check smtp accessibility.