Shop OBEX P1 Docs P2 Docs Learn Events
SMTP user name and password using HTTPServer — Parallax Forums

SMTP user name and password using HTTPServer

lfreezelfreeze Posts: 174
edited 2013-05-01 04:08 in Accessories
After an awful lot of failed tests, I thought it best to appeal for help!!!

I am using HTTPServer I plugged in the email Code from the tutorial. I noticed at the very bottom of the tutorial page this item:

“Your SMTP server might require a username and password. Is so, the username and password must be base 64 encoded”

My SMTP server does require both user name and password. I converted both items
To base64, but have no idea how to plug them into the email program. Suggestions about
how to do this will be greatly appreciated.

Thank you.

Larry

Comments

  • Mike GMike G Posts: 2,702
    edited 2013-04-04 13:10
    Before you go any further you need to make sure the email server does not use TLS encryption. The SMPT code will not work with TLS encryption.

    Otherwise add the username and password as two more socket.tcp tx to the SMTP conversation.
  • lfreezelfreeze Posts: 174
    edited 2013-04-04 17:05
    Thanks for the response, After searching I find that Comcast uses SSL encryption. I included
    Username and password (base64) in the modified email section. I included the Additional DAT items.
    I then used the RTC to generate an email once each minute at the 40 second mark

    The program (attached) loads and runs. It hangs at “conversation log” and no email is generated.
    For security I xxxxD out some of the obvious items.
    I don’t know how to proceed, I have double checked my Comcast settings, and find they are correct.
    Please point me in the right direction

    Thanks.
    Larry
  • Mike GMike G Posts: 2,702
    edited 2013-04-05 06:41
    Sorry Larry, SMTP will not work. HTTPServer can not handle SSL (TLS encryption) certs.
  • lfreezelfreeze Posts: 174
    edited 2013-04-05 11:06
    Thanks Mike, before giving up, I called Comcast to confirm the encryption, /they told me SSL was optional and had to be Selected by the user

    For testing purposes I configured the Spinmail demo from Beau Schwabe. Here are the settings
    I used in Spinmail

    MACaddr byte "00:08:DC:16:F3:E3",0 '<-- Your Spinneret Hardware MAC address
    IPaddr byte "192.168.2.99",0 '<-- Your Network Spinneret IP address
    GWaddr byte "192.168.2.1",0 '<-- Your Network Spinneret Gateway address
    ''
    SMTPport word 587 '<-- SMTP port (program designed for port 587)
    SMTP byte "{smtp.comcast.net}",0 '<-- Your SMTP server providers name
    IPsmtp byte "68.87.26.155",0 '<-- Find this by pinging your SMTP server name
    ''
    UserName byte "xxxxxxx@comcast.net",0 '<-- Your E-mail (must be registersd with SMTP)
    Password byte "xxxxxxxxxxxxxxxxxxx“,0 '<-- This is base64 encoded before it is sent
    T0 byte "xxxxxxxxx@comcast.net",0 '<-- Who you are sending to (any valid address)
    Subject byte "[SpinMail] - Test",0 '<-- Subject line of E-mail
    ''
    Body byte "This is a test E-mail message sent from a Spinneret !",13,10,13,10
    byte "Thanks for playing",13,10,13,10
    byte "Beau Schwabe",0

    I loaded and ran it, it worked and produced emails. I used the same settings in HTTPServer and could not get it to work. I think I have some fat finger, bonehead mistake in the Modified HTTServer, but cannot find it.

    Any thoughts or comments would be appreciated.

    Larry
  • Mike GMike G Posts: 2,702
    edited 2013-04-06 07:36
    Larry, The AUTH LOGIN command must be sent before sending a username and password. Send AUTH LOGIN right after EHLO. See the untested code snippet below. Literally, the SMTP protocol is like a conversation with the SMTP server. The SPIN code mimics this conversation. A good way practice SMTP is using telnet to manually to send a few emails. That's how I figure out how to do the SMTP thing.

    Here's a how to - Note: AUTH LOGIN has a space between AUTH and LOGIN.
    http://technet.microsoft.com/en-us/library/aa995718%28v=exchg.65%29.aspx

    Once you get telnet SMTP working, the SPIN logic will be a breeze.

    Lastly, I'm not sure about the RTC/eMail COG process. First, the process starts before any socket are initialized. That's probably okay but the SendTestEmail method assumes the socket is already up and running. Also, consider testing the SMTP code by itself until you get the emails going. Otherwise there are too many moving parts.


    PUB SendTestEmail(id) | size, tempMask, wait
        
        tempMask := tcpMask
        SetTcpSocketMaskById(id, 0)
        
        wait := 200
        
        Socket.Close(id)
        pause(delay)
        InitializeSocketForEmail(id)
        pause(delay)
        
        ' Connect to the mail server
        pst.str(string(13, "Connecting to mail server"))
        
        Socket.Connect(id)
        pause(wait)
        repeat while !Socket.Connected(id)
        
        pst.str(string(13,"Connected... Talking with mail server"))
        
        'Send greeting
        StringSend(id, string("HELO youremail@email.com", 13, 10))
        pause(wait)
    
    
    '==============================================================================
        StringSend(id, string("AUTH LOGIN", 13,10)
        pause(wait)
    
    '    'Send user name
         StringSend(id, string("bGZyZWV6ZQ==", 13, 10))   
    '
    '
    '    'Send password
         StringSend(id, string("TXJtaWNrZXkxMjM=", 13, 10))  
    '==============================================================================
        
        ' From Address
        StringSend(id, string("MAIL FROM: ", 13, 10))
        pause(wait)
        
        ' To Address
        StringSend(id, string("RCPT TO: ", 13, 10))
        pause(wait)
        
        'Start of the email content
        StringSend(id, string("DATA", 13, 10))
        pause(wait)
        
        'Subject line
        StringSend(id, string("SUBJECT: Email from the Spinneret", 13, 10))
        pause(wait)
        
        'Email body
        StringSend(id, string("Hello from the Spinneret.", 13, 10))
        pause(wait)
        
        'Quit conversation
        StringSend(id, string(".", 13, 10))
        pause(wait)
        
        StringSend(id, string("QUIT", 13, 10))
        pause(wait)
        
        pst.str(string(13,"Done",13))
        pst.str(string(13,"Conversation Log",13))
        
        'Display log
        repeat until size := Socket.rxTCP(id, @rxdata)
        pst.str(@rxdata)
        
        pst.str(string(13, "Disconnect and reset socket: "))
        pst.dec(id)
        pst.char(13)
        
        ' Reset the socket
        Socket.Disconnect(id)
        pause(delay)
        
        ' Reset the tcpMask 
        tcpMask := tempMask
        
        InitializeSocket(id)
        pause(delay)
        
        return
    
  • lfreezelfreeze Posts: 174
    edited 2013-04-08 14:38
    Mike

    Your suggestion got me going in the right direction. After a few failed attempts,
    I was able to telnet an email message via Comcast. I saved the log and will use it to
    back in the logic statements into the program. Without your generous help, I would still
    be stuck in the mud, thank you!

    Larry
  • lfreezelfreeze Posts: 174
    edited 2013-04-29 10:05
    Still stuck, Please help!

    I carefully followed the email portion of the “Spinneret Setup” tutorial, but still no luck. I set up a telnet Session and added
    the “to:”, “from:”, “subject: ” and “body:” commands to the telnet sessions, I tried it many times and each was successful.

    I modified httpserver with port2, emailip and emailport. I added the “to:”, “from:”, “subject: ” and “body:” commands, to
    the httpserver program. I ran the program and it produced the following conversation log. It was not successful , no emails
    were received, obviously I have made a mistake as the commands I added are not being referenced in the conversation log.
    The modified httpserver program is attached.

    I have xxx’d out my address info to delay the spammers.

    Conversation Log
    220 omta21.westchester.pa.mail.comcast.net comcast ESMTP server ready
    250 omta21.westchester.pa.mail.comcast.net hello [68.44.187.178], pleased to meet you
    334 VXNlcm5hbWU6
    334 UGFzc3dvcmQ6
    235 2.7.0 ... Authentication succeeded
    250 2.1.0 <xxxxxx@comcast.net> sender ok
    250 2.1.5 <xxxxxx@comcast.net> recipient ok
    354 enter mail, end with "." on a line by itself
    250 2.0.0 Vrwo1l00M3rNTWC3hrwqTu mail accepted for delivery
    221 2.0.0 omta21.westchester.pa.mail.comcast.net Comcast closing connection
    Disconnect and reset socket: 2

    Thank you….Larry
  • Mike GMike G Posts: 2,702
    edited 2013-04-29 16:32
    Larry, I tested the AUTH LOGIN script and it worked with my ISP. I placed the call to the SMTP method, SendTestEmail(0), right below Main(). The server sends an email then starts up the web server listeners.
    PUB Main | packetSize, id, i, reset, j, temp
      ''HTTP Service
    
      SendTestEmail(0)
    
    PUB SendTestEmail(id) | size, tempMask, wait
        
        tempMask := tcpMask
        SetTcpSocketMaskById(id, 0)
        
        wait := 200
        
        Socket.Close(id)
        pause(delay)
        InitializeSocketForEmail(id)
        pause(delay)
        
        ' Connect to the mail server
        pst.str(string(13, "Connecting to mail server"))
        
        Socket.Connect(id)
        pause(wait)
        repeat while !Socket.Connected(id)
        
        pst.str(string(13,"Connected... Talking with mail server"))
        
        'Send greeting
        StringSend(id, string("HELO youremail@email.com", 13, 10))
        pause(wait)
    
    
    '==============================================================================
        StringSend(id, string("AUTH LOGIN", 13,10))
        pause(wait)
    
    '    'Send user name
         StringSend(id, string("encrypted username", 13, 10))  
    '
    '    'Send password
         StringSend(id, string("encrypted password", 13, 10)) 
    '==============================================================================
        
        ' From Address
        StringSend(id, string("MAIL FROM: someemail@email.com", 13, 10))
        pause(wait)
        
        ' To Address
        StringSend(id, string("RCPT TO: someemail@email.com", 13, 10))
        pause(wait)
        
        'Start of the email content
        StringSend(id, string("DATA", 13, 10))
        pause(wait)
        
        'Subject line
        StringSend(id, string("SUBJECT: Email from the Spinneret", 13, 10))
        pause(wait)
        
        'Email body
        StringSend(id, string("Hello from the Spinneret.", 13, 10))
        pause(wait)
        
        'Quit conversation
        StringSend(id, string(".", 13, 10))
        pause(wait)
        
        StringSend(id, string("QUIT", 13, 10))
        pause(wait)
        
        pst.str(string(13,"Done",13))
        pst.str(string(13,"Conversation Log",13))
        
        'Display log
        repeat until size := Socket.rxTCP(id, @rxdata)
        pst.str(@rxdata)
        
        pst.str(string(13, "Disconnect and reset socket: "))
        pst.dec(id)
        pst.char(13)
        
        ' Reset the socket
        Socket.Disconnect(id)
        pause(delay)
        
        ' Reset the tcpMask 
        tcpMask := tempMask
        
        InitializeSocket(id)
        pause(delay)
        
        return
    

    I noticed in the posted source there are two TO and FROM parameters. One set is invoked after the DATA command. I tried that as well and it worked but I suppose it can cause problems. There should only be one FROM. But doing so seems to create an email spoof. The email could get picked up by SPAM monitors or virus checkers.
        ' From Address
        StringSend(id, string("MAIL FROM:xxxxxxxxxxx@comcast.net ", 13, 10))
        pause(wait)
        
        ' To Address
        StringSend(id, string("RCPT TO:xxxxxxxxxxx@comcast.net ", 13, 10))
        pause(wait)
        
        'Start of the email content
        StringSend(id, string("DATA",13,10))
        pause(wait)
    
    
       'to line
        StringSend(id, string("to:xxxxxxxx@comcast.net", 13, 10))
        pause(wait)
    
    
      'from line
        StringSend(id, string("from:xxxxxxxxxx@comcast.net", 13, 10))
        pause(wait)
    
  • RforbesRforbes Posts: 281
    edited 2013-04-29 16:41
    Hey Larry,

    I haven't tried doing anything with email yet so I can't help you much- however, I have a suggestion that may or may not help. It helped a lot with using the spinneret as an FTP client, and you might have success with it for your smtp stuff. With FTP, you generally need to receive a response after each command to ensure the server actually processed the command correctly (or not) before sending the next command.

    Since the mail server is returning responses with each command you send, try this:

    Send your first string
    Get your response.

    Send your next string
    Get your response.

    On and on.

    Getting your response can be a simple method with a loop this:
    pri get_response|tries,size
    
      bytefill(@rxdata, 0, RxTx_BUFFER)
      tries:=0
      size:=0
    
      repeat while size==0
        size := Socket.rxTCP(id, @rxdata)
        Pause(50)
        tries++
        if tries == 360
          Cancel_Mail(id)
    
      pst.str(string("Response:",13))
      pst.str(@rxdata)
      pst.newline
    
    

    By doing this, you'll be getting the response from each command and you can "do something" if you timeout before you get a response. Your conversation log will be more dynamic, and the "Cancel_Mail" method can be anything you want- a pst message, an abort (with or without value) etc etc.

    It's not a perfect method for getting responses, but it certainly helps to let you see what's happening each step of the way.

    Your SendTestEmail method have something like this for each chunk of information you're sending to the server:
    StringSend(id, string("MAIL FROM:xxxxxxxxxxx@comcast.net ", 13, 10))
    get_response
    StringSend(id, string("RCPT TO:xxxxxxxxxxx@comcast.net ", 13, 10))
    get_response
    
  • lfreezelfreeze Posts: 174
    edited 2013-04-30 08:15
    Hi Mike,

    Thanks for the suggestion, I incorporated it into httpserver 4 29 2013 M. The results showed that the
    Server accepted everything up to and including the “data” command. The server ignored
    (no response) Everything after that up to the “.” command then continued and closed the connection.

    I’m stumped!!

    I then did a telnet session from the command line, using the same statements. It was successful.

    This is what the command line telnet session looked line:

    220 omta24.westchester.pa.mail.comcast.net comcast ESMTP server ready
    ehlo smtp.comcast.net
    250-omta24.westchester.pa.mail.comcast.net hello [68.44.187.178], pleased to meet you
    250-HELP
    250-AUTH LOGIN PLAIN
    250-SIZE 36700160
    250-ENHANCEDSTATUSCODES
    250-8BITMIME
    250-STARTTLS
    250 OK
    auth login
    334 VXNlcm5hbWU6
    bxxxxxxxxxxxxxxxxx0Lm5ldA==
    334 UGFzc3dvcmQ6
    TxxxxxxxxxxxxxxxMjM=
    235 2.7.0 ... Authentication succeeded
    mail from:xxxxxx@comcast.net
    250 2.1.0 <xxxxxxx@comcast.net> sender ok
    rcpt to:xxxxxxxx@comcast.net
    250 2.1.5 <xxxxxxxx@comcast.net> recipient ok
    data
    354 enter mail, end with "." on a line by itself
    to:xxxxxx@comcast.net
    from:xxxxxxxx@comcast.net
    subject:test message

    test message via telnet session
    .
    250 2.0.0 WEn11l00D3rNTWC3kEoRqg mail accepted for delivery
    quit
    221 2.0.0 omta24.westchester.pa.mail.comcast.net comcast closing connection
    Connection to host lost.
  • lfreezelfreeze Posts: 174
    edited 2013-04-30 13:43
    After many attempts, I was finally successful. The mistake was painfully simple,
    The desktop I was using to receive the emails from the spinneret did not have the
    email account spinneret was sending to activated on it.

    I am still confused about why I was able to telnet a good Email message to
    the same email address. I will not argue with success. Thanks for your help, the
    monitoring method forced me to continue testing and Eventually reach a solution.

    Larry
  • RforbesRforbes Posts: 281
    edited 2013-04-30 13:43
    Larry,

    I see this in your posted code:
        'Quit conversation
        StringSend(id, string(".", 13, 10))
        pause(wait)
    

    Silly as it may seem, it says to enter a "." on a line by itself. Perhaps removing the cr 13 will do the trick. You've stated your responses from the server were fine up to and including the "data" command... at that point, the server is waiting for your stuff, followed by a "." and then it processes the stuff. It's also fine AFTER your stuff, because it accepted and processed the QUIT command. So it didn't get the correct data format for all your stuff.

    Just a guess. Good luck.
  • Mike GMike G Posts: 2,702
    edited 2013-04-30 18:37
    Glad to hear you got it working. This network stuff can be a bit frustrating - lots of moving parts.

    I like using WireShark to monitor network traffic. It's a big help to see requests and responses flying by on the screen. The learning curve is not too steep.
  • lfreezelfreeze Posts: 174
    edited 2013-05-01 04:08
    Mike, Robert, Thank you both for your suggestions. Coding network stuff is on a
    Par with going to the dentist. Happily for my simple project it worked out okay. I will
    Take a look at “wireshark” hopefully it is not to far above my skill set.

    Larry
Sign In or Register to comment.