<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:foaf="https://xmlns.com/foaf/0.1/" xmlns:og="https://ogp.me/ns#" xmlns:rdfs="https://www.w3.org/2000/01/rdf-schema#" xmlns:schema="https://schema.org/" xmlns:sioc="https://rdfs.org/sioc/ns#" xmlns:sioct="https://rdfs.org/sioc/types#" xmlns:skos="https://www.w3.org/2004/02/skos/core#" xmlns:xsd="https://www.w3.org/2001/XMLSchema#" version="2.0" xml:base="https://www.linuxjournal.com/tag/smtp">
  <channel>
    <title>SMTP</title>
    <link>https://www.linuxjournal.com/tag/smtp</link>
    <description/>
    <language>en</language>
    
    <item>
  <title>Sending Email with Netcat</title>
  <link>https://www.linuxjournal.com/content/sending-email-netcat</link>
  <description>  &lt;div data-history-node-id="1011489" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-field-node-image field--type-image field--label-hidden field--item"&gt;  &lt;img src="https://www.linuxjournal.com/sites/default/files/nodeimage/story/cat_eyes.jpeg" width="200" height="120" alt="" title="Sending Email with Netcat" typeof="foaf:Image" class="img-responsive" /&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/pete-vargas-mas" lang="" about="https://www.linuxjournal.com/users/pete-vargas-mas" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Pete Vargas Mas&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;Is it possible to send an email from a host that has no email client software installed?  As long as you have &lt;a href="https://netcat.sourceforge.net/"&gt;netcat&lt;/a&gt;, of course it is!&lt;/p&gt;
&lt;p&gt;Netcat (/usr/bin/nc on Red Hat Enterprise Linux systems) is a simple utility for reading and writing data across TCP/UDP connections. It's often used for testing and debugging network connections. In its most basic usage, netcat allows you to feed a stream of data to a specific port on a specific host, which is perfect for our purpose here. Check the netcat man page for more information on it's various features. There are also sample scripts under /usr/share/doc/nc-*/. If netcat is not installed on your Red Hat Enterprise Linux, CentOS or Fedora system, you can install it with the command &lt;tt&gt;yum install nc&lt;/tt&gt;.&lt;/p&gt;
&lt;p&gt;What we will be doing with netcat is using it to feed a stream of data to port 25 (SMTP) on a mail relay, making it believe it's talking to a regular email client. In order to do this, we first need to figure out what our email server expects to see from a client. This can be done by connecting via telnet to our SMTP relay host and issuing the correct SMTP commands, as in the following example:&lt;/p&gt;
&lt;pre&gt;
   [user@host]# telnet smtp.domain.com 25
   Trying 192.168.0.1...
   Connected to smtp.domain.com (192.168.0.1).
   Escape character is '^]'.
   220 myrelay.domain.com ESMTP
   HELO smtp.domain.com
   250 myrelay.domain.com
   MAIL FROM:&lt;alice@hacker.com&gt;
   250 sender &lt;alice@hacker.com&gt; ok
   RCPT TO:&lt;bob@secure.net&gt;
   250 recipient &lt;bob@secure.net&gt; ok
   DATA
   354 go ahead
   From: [Alice Hacker] &lt;alice@hacker.com&gt;
   To: [Bob Smith] &lt;bob@secure.net&gt;
   Date: Mon, 12 Apr 2010 14:21:26 -0400
   Subject: Test Message

   Hi there!
   This is supposed to be a real email...

   Have a good day!
   Alice


   .
   250 ok:  Message 222220902 accepted
   QUIT
   221 myrelay.domain.com
   Connection closed by foreign host.
   [user@host]#
&lt;/pre&gt;&lt;p&gt;
Note that the userid part of the "From" address does not have to contain a valid userid, only a valid domain name. You will have to replace "smtp.domain.com" with a valid SMTP relay that allows relaying from your host. Generally, experienced admins will disallow relaying from unknown hosts to discourage spam. Additionally, the body of the email (everything after the "DATA" command) is ended by sending a blank line, followed by a line with a period (.) on it by itself.&lt;/p&gt;
&lt;p&gt;Now that we know what the remote server expects to see, we can craft a text file with our SMTP commands and the message to be sent. The recipients mail server will expect the date to be in a particular format.&lt;/p&gt;
&lt;p&gt;Use the command:  &lt;/p&gt;
&lt;pre&gt;
date '+%a, %d %b %Y %H:%M:%S %z'
&lt;/pre&gt;&lt;p&gt;
To generate a date string that resembles:&lt;/p&gt;
&lt;pre&gt;
Mon, 12 Apr 2010 14:21:26 -0400
&lt;/pre&gt;&lt;p&gt;
The contents of your message file should resemble this example:&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/sending-email-netcat" hreflang="und"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Tue, 20 Apr 2010 17:04:52 +0000</pubDate>
    <dc:creator>Pete Vargas Mas</dc:creator>
    <guid isPermaLink="false">1011489 at https://www.linuxjournal.com</guid>
    </item>

  </channel>
</rss>
