logo
Send an email from the command line
Sending mail from your *nix account
Sending mail through your ISP
Add headers
Merging the two previous methods
Send emails without using netcat

Send an email from the command line

Sending mail from your *nix account

In the first case you will need on your machine a running mail server like postfix, sendmail or other...
Now to send an email from your user on your machine to another user on another machine.
To do this enter the following code:
mail recipient@email.com
 Subject: mail test from command line
 Here is the content of the mail
 the second line of content...
 
When you have finished entering the body content of the message, simply enter the combination 'ctrl-d' to indicate the end of the file. And voila ! your mail should be sent.
To send a message to another user in the same local machine, simply enter his username instead of email address.

Sending mail through your ISP

Send an email via your ISP allows you to specify more the email address of the sender. It is very easy to spoof an email address that way. Attention spoofing is prohibited and your actions leave traces.
To send this email we use 'netcat' or 'telnet'. At first retrieve the address of the mail server of your ISP.
Enter then the following command:
nc smtp.yourISP.com 25
Then say hello:
ehlo bob
There is not a typo it is 'ehlo'. Now give him the address of the sender:
MAIL FROM: <sender@server.com>
If all goes well your ISP must respond ok. Give him the recipient.
RCPT TO: <recipient@server.com>
To move to the message body write DATA and press the ENTER key
DATA
354 End data with <CR><LF>.<CR><LF>
This is the body of my mail.
.
 
End your message with a new line starting with a '.'. Enter 'quit' to quit.

Add headers

It is possible to add headers in the message body to specify the date, subject, send a copy...

Merging the two previous methods

You can simply, when you email daemon is running on your machine, talk to it via 'telnet' or 'netcat'.
 
hanoo@hp_laptop% nc 127.0.0.1 25
220 hp_laptop.localdomain ESMTP Postfix
EHLO man
250 hp_laptop.localdomain
MAIL FROM: <netcat@postfix.com>
250 2.1.0 Ok
RCPT TO: <target@host.com>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
This is the body of my mail,
this is the second line...
.
250 2.0.0 Ok: queued as 9C12E7F404
 

Send emails without using netcat

Know that 'netcat' and 'telnet' are available in windows, linux and mac and that in android you have 'telnet' which works the same way for this purpose as 'netcat'.
It should be noted that it is also possible to use '/dev/tcp' in bash and 'TCP_Send' in zsh.
Be The First To Comment.

Add a comment:





You can use these HTML tags: <br><a><i><b>