title: Python and Scapy: plain text SMTP session
body: <p>Is it possible to perform the the simplest <code>SMTP</code> session using <a href="http://www.secdev.org/projects/scapy/" rel="nofollow">Scapy</a>? 
  I tried to read captured with <code>tcpdump</code> using <code>Scapy</code> and to send packets, but no luck...</p>
  
  <p>This is what I have</p>
  
  <pre><code>#!/usr/bin/python
  from scapy.all import *
  from scapy.layers.inet import IP, TCP
  source_ip = '1.2.3.4'
  source_port = 5100 
  source_isn = 1000
  dest_ip = '1.2.3.5' 
  dest_port = 25
  ip=IP(src=source_ip, dst=dest_ip)
  SYN=TCP(sport=source_port, dport=dest_port, flags="S", seq=source_isn)
  SYNACK=sr1(ip/SYN)
  source_isn = SYN.seq + 1
  source_ack = SYNACK.seq + 1
  CK=TCP(ack=source_ack, sport=source_port, dport=dest_port, flags="A",seq=source_isn)
  handshakedone=sr1(ip/ACK)
  DTA=TCP(ack=handshakedone.seq+len(handshakedone.load), seq=source_isn, sport=source_port,dport=dest_port,flags="PA")
  sr(ip/DTA/Raw(load='mail from: test@gmail.com\r\n'))
  send(ip/DTA/Raw(load='rcpto to: me@gmail.com\r\n'))
  source_isn = ACK.seq + len(mfrom)
  .....
  RST=TCP(ack=SYNACK.seq + 1, seq=source_isn, sport=source_port, dport=dest_port, flags="RA")
  send(ip/RST)
  </code></pre>
  
  <p>Handshake is successful but what <code>ACK</code> and <code>SEQ</code> values should be during the session? How can I calculate them?</p>