Computer Science Canada

Turing and "NET" (emails)

Author:  TokenHerbz [ Tue Jan 25, 2011 5:10 pm ]
Post subject:  Turing and "NET" (emails)

I know it's possible to look up web pages, even create a chat program or a connection over the internet.

But is there a way that i could send an email using Turing (For non Malicious Reasons).

I'm interested in knowing how it works, and why it wont work (which ever applies) and the concepts behind them.

Author:  ProgrammingFun [ Tue Jan 25, 2011 5:19 pm ]
Post subject:  RE:Turing and "NET" (emails)

Why would you want to use Turing? It will lag way too much...
Do you mean accessing an HTML based email (Gmail, Hotmail, Yahoo!) or a program such as Outlook?

Author:  2goto1 [ Tue Jan 25, 2011 5:21 pm ]
Post subject:  RE:Turing and "NET" (emails)

I'd speculate that it would work perfectly fine if you launch a command line process using Sys.Exec, http://compsci.ca/holtsoft/doc/sys_exec.html. You could invoke a send mail script (that you would have to write, using any programming language or scripting language of your choice). That's one way to do it in case Turing doesn't have the capability built-in.

Author:  DemonWasp [ Tue Jan 25, 2011 5:27 pm ]
Post subject:  RE:Turing and "NET" (emails)

Since Turing supports network streams, you can implement (some of): POP3, SMTP, IMAP. All of these protocols can be used for mail, among several others. Basically, you're going to end up sending messages by put-ing text through a TCP stream, then get-ing the server's responses and interpreting them.

Turing does not have a built-in email library. Few languages do, I suspect.

Author:  2goto1 [ Tue Jan 25, 2011 5:36 pm ]
Post subject:  RE:Turing and "NET" (emails)

Most enterprise-friendly languages have a built-in library to send emalis. I.e. Java, http://www.tutorialspoint.com/java/java_sending_email.htm, .NET, http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx, PHP, http://email.about.com/od/emailprogrammingtips/qt/How_to_Send_Email_from_a_PHP_Script.htm, etc.

Granted, a lot of the APIs that are native to those languages don't necessarily support everything that you could by writing your own SMTP session exchange at the TCP API level...that gives you total flexibility.

Author:  TokenHerbz [ Tue Jan 25, 2011 5:41 pm ]
Post subject:  RE:Turing and "NET" (emails)

well to send a message to my friends hotmail address, is what i was aiming for.

2onego1: your link in 1st post is broken //infact all are broken

Author:  Tony [ Tue Jan 25, 2011 5:53 pm ]
Post subject:  RE:Turing and "NET" (emails)

Except that if you are running your own mail server, email deliverability turns out to be a _difficult_ problem. This is why companies like MailChimp can charge up to $0.03 (much cheaper at volume) per email that they send out on your behalf.

edit: 2onego1's links incorrectly include trailing commas.

Author:  TokenHerbz [ Tue Jan 25, 2011 5:59 pm ]
Post subject:  RE:Turing and "NET" (emails)

Could someone assist me with the SMTP? seems to be what im looking for. Do i have to script this with something else outside of turing, or since turing can use NET i can probly do it with turing?

Author:  TokenHerbz [ Tue Jan 25, 2011 6:00 pm ]
Post subject:  RE:Turing and "NET" (emails)

I dont want to run a server, I jsut want for example, "Hey there" -> it sends that "HEY THERE" to his hotmail address. No need to recall etc. just sending info to hotmail adress.

Author:  Tony [ Tue Jan 25, 2011 6:08 pm ]
Post subject:  RE:Turing and "NET" (emails)

You need a server. If you don't want to run one locally, you can connect to a remote one via POP3/SMTP/IMAP (depending on what a remote server supports).

Author:  TokenHerbz [ Tue Jan 25, 2011 6:11 pm ]
Post subject:  RE:Turing and "NET" (emails)

okay how would we go about using simple mail transfer protocal?

I don't understand how we can use an IP to send the email to a SPECIFIC email adress. IP is the web site, not the actual mail recipiant to that web site.

Author:  2goto1 [ Tue Jan 25, 2011 6:13 pm ]
Post subject:  Re: RE:Turing and "NET" (emails)

TokenHerbz @ Tue Jan 25, 2011 5:41 pm wrote:
well to send a message to my friends hotmail address, is what i was aiming for.

2onego1: your link in 1st post is broken //infact all are broken


The compsci forum software encoded a comma at the end of each of my links. The commas were meant to separate the links from one another, I'll have to keep that in mind next time. Just copy & paste the links, and remove the trailing comma for them to work

Author:  Tony [ Tue Jan 25, 2011 6:16 pm ]
Post subject:  RE:Turing and "NET" (emails)

Not quite, TCP/IP includes an address (IP) of a machine on a network, and a port number. That machine could be running many services, commonly a webserver (port 80 for HTTP traffic, which is almost always omitted for convenience, but implicitly is still there as a silent default) or a mail server or a game server, etc.

Author:  2goto1 [ Tue Jan 25, 2011 6:21 pm ]
Post subject:  Re: Turing and "NET" (emails)

If you have a Google account, you can send email through it. I've done that on numerous occasions for testing purposes. Here's a sample of doing that (links should be working, I've tested that my punctuation isn't getting in the way):

http://stackoverflow.com/questions/757987/send-email-via-c-through-google-apps-account

If you want to write the SMTP communication yourself, you can do so. Try using a telnet session and create a simple SMTP hello world session, i.e.

http://hanez.org/howto-telnet-smtp.html

Once you're able to do that, you just have to take the commands that you've used in the telnet session, and program them with the Turing network APIs.

Author:  TokenHerbz [ Tue Jan 25, 2011 6:39 pm ]
Post subject:  RE:Turing and "NET" (emails)

Turing:

var SMTP_port : int := 25
var stream : int
var HOST_ADDRESS : string := Net.HostAddressFromName("www.hotmail.com")
stream := Net.OpenConnection(HOST_ADDRESS,SMTP_port)
if stream <= 0 then
    put "NO GO!"
end if
put ""
put "CONNECTED TO ", HOST_ADDRESS
put ""
%%so we connected to hotmail? now we sent it info ??
%%makes no sense but lets try it anyways,,

put : stream, "HELO local.domain"
delay(5000)  %%should be suffice enough time to get reply no?
if Net.LineAvailable (stream) then
    var line : string
    get : stream, line : *
    put line
end if
%%SHOULD GET A REPLAY FROM SERVER?!?


I'm not understanding this i'm pretty sure... because this makes no sense, but these examples and info i have aren't great.

Could someone explain better then those web sites?

Author:  chrisbrown [ Tue Jan 25, 2011 7:23 pm ]
Post subject:  Re: Turing and "NET" (emails)

First, instead of www.hotmail.com, you want to connect to smtp.live.com. That change should at least give you some response text to look at.

Second, local.domain probably means your ip address, but I don't know how significant it is.

Finally, this procedure might help you. Call it immediately after establishing a connection, as well as after sending each command.

Turing:

proc getAndPrintResponse (stream : int)
    var t := Time.Elapsed
    var c : char
    loop
        if Time.Elapsed - t > 5000 then
            put "Timeout waiting for response"
            return
        elsif Net.CharAvailable (stream) then
            loop
                if not Net.CharAvailable (stream) then
                    put ""
                    return
                end if
                get : stream, c
                put c..
            end loop
        end if
    end loop
end getAndPrintResponse



Also: You might have more luck using Google: smtp.gmail.com.

Author:  TokenHerbz [ Tue Jan 25, 2011 9:27 pm ]
Post subject:  RE:Turing and "NET" (emails)

just times out constantly.... with both.

Author:  DemonWasp [ Wed Jan 26, 2011 1:50 am ]
Post subject:  RE:Turing and "NET" (emails)

I took a very brief look at this and got as far as asking for mail, which returns the server error message "530 Must issue a STARTTLS command first", which means that the server wants me to securely authenticate. This would require implementing TLS encryption (probably not impossible in Turing, just tedious and lengthy).

Turing:

% Wait until an entire line is available on the given stream, then read it into
% the given variable. Note the (optional) debug printing statement.
proc NET_RECV_LINE ( stream : int, var line : string )
    loop
        exit when Net.LineAvailable ( stream )
        delay ( 10 )    % avoid a strict busy-wait
    end loop
    get : stream, line : *
   
    put line
end NET_RECV_LINE


const SMTP_PORT : int := 25
const HOST : string := "smtp.gmail.com"
const HOST_ADDRESS : string := Net.HostAddressFromName ( HOST )

put "Connecting to "+HOST+" at "+HOST_ADDRESS
 
var stream : int := Net.OpenConnection ( HOST_ADDRESS, SMTP_PORT )
 
if stream <= 0 then
    put "Connection failed"
    return
end if

put "Connection succeeded"

var line : string := ""

NET_RECV_LINE ( stream, line )      % 220 mx.google.com ESMTP

put : stream, "HELO my.example.com"

NET_RECV_LINE ( stream, line )      % 250 mx.google.com at your service

put : stream, "MAIL FROM:<YourEmail@gmail.com>"

NET_RECV_LINE ( stream, line )      % 530 5.7.0 Must issue a STARTTLS command first.


Author:  chrisbrown [ Wed Jan 26, 2011 2:59 am ]
Post subject:  Re: RE:Turing and "NET" (emails)

DemonWasp @ Wed Jan 26, 2011 1:50 am wrote:
I took a very brief look at this and got as far as asking for mail, which returns the server error message "530 Must issue a STARTTLS command first", which means that the server wants me to securely authenticate.

If you send AUTH LOGIN after your HELO, you can submit Base64 credentials -- to Gmail, at least.
Turing:

proc flush (stream : int)
    var c : char
    loop
        exit when not Net.CharAvailable (stream)
        get : stream, c
        put c ..
    end loop
    put ""
end flush

proc printResponse (stream : int)
    var t := Time.Elapsed
    loop
        if Time.Elapsed - t > 5000 then
            put "Timeout waiting for response"
            return
        elsif Net.CharAvailable (stream) then
            flush (stream)
            return
        end if
    end loop
end printResponse

proc sendAndPrintResponse (stream : int, str : string)
    put str
    put : stream, str
    printResponse (stream)
end sendAndPrintResponse


const SMTP_PORT := 25
const SMTP_SERVER := "smtp.gmail.com"
const SMTP_ADDRESS := Net.HostAddressFromName (SMTP_SERVER)
const END_OF_BODY := "\r\n.\r\n"    %Don't change this

% You must have a valid Gmail account.
const UNAME_64 := "Gmail Username"  % Must be Base64-encoded. Here's an encoder:
const PWORD_64 := "Gmail Password"  % http://www.motobit.com/util/base64-decoder-encoder.asp

% Email Content
const MAIL_FROM := "Sender's email"
const SEND_TO := "Recipient's email"
const SUBJECT_TEXT := "Test Subject"
const BODY_TEXT := "Test Body"


setscreen ("text")


var stream := Net.OpenConnection (SMTP_ADDRESS, SMTP_PORT)
if stream > 0 then
    put "Connection established with ", SMTP_SERVER, " @ ", SMTP_ADDRESS
    printResponse (stream)
else
    put "Connection attempt timed out"
    return
end if


sendAndPrintResponse (stream, "EHLO " + Net.LocalName)

sendAndPrintResponse (stream, "AUTH LOGIN")

sendAndPrintResponse (stream, UNAME_64)

sendAndPrintResponse (stream, PWORD_64)

sendAndPrintResponse (stream, "MAIL FROM: " + "<" + MAIL_FROM + ">")

sendAndPrintResponse (stream, "RCPT TO: " + "<" + SEND_TO + ">")

sendAndPrintResponse (stream, "DATA")

sendAndPrintResponse (stream, "Subject:" + SUBJECT_TEXT + "\n" + BODY_TEXT + END_OF_BODY)


Author:  TokenHerbz [ Wed Jan 26, 2011 6:21 am ]
Post subject:  RE:Turing and "NET" (emails)

That seems to work better, i get replys from the servers.

I've tried to use hotmail (since i cant make Gmail account)

Im connecting to smtp.live.com port : 587 (25didnt work)

reply:
code:

Connection established with smtp.live.com @ 65.55.162.200
220 BLU0-SMTP191.blu0.hotmail.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.4675 ready at  Wed, 26 Jan 2011 03:12:10 -0800


"HELO local.domain" doesn't get a reply, which im reading it should. even (EHLO) doesn't (as printed above) .. iv'e increased response times to, the rest times out.

Iv'e used Base64 encryptions for my user/pass (and was attempting to send little data) to the same account. ( should be possible to send something to yourself, can do it in hotmail)

Any ideas? I don't think i have to set up any POP3 configurations since im not trying to access the client server right... So i'm at a loss, more tips please thank you.

Author:  2goto1 [ Wed Jan 26, 2011 7:57 am ]
Post subject:  RE:Turing and "NET" (emails)

It sounds like hotmail may require that your SMTP connection is TLS/SSL based:

http://techblissonline.com/hotmail-pop3-and-smtp-settings/

Author:  TokenHerbz [ Wed Jan 26, 2011 8:55 am ]
Post subject:  RE:Turing and "NET" (emails)

even with that i still cant pass this crutch i'm stuck in. I've even been trying/reading about this stuff but i can't find anything on "How it works"...

I think for me to understand how it works or why it works would be a big help cause all this C and VB codes are useless unless i can understand it.

f u s t e r a t i n g Sad

Author:  TokenHerbz [ Wed Jan 26, 2011 9:25 am ]
Post subject:  RE:Turing and "NET" (emails)

WOW Awesome thanks to every one for the assistance, I HAVE IT WORKING!~!!!

Author:  2goto1 [ Wed Jan 26, 2011 9:44 am ]
Post subject:  RE:Turing and "NET" (emails)

Cool, what parts of the code are confusing?

Author:  ProgrammingFun [ Wed Jan 26, 2011 11:36 am ]
Post subject:  Re: RE:Turing and "NET" (emails)

TokenHerbz @ Wed Jan 26, 2011 9:25 am wrote:
WOW Awesome thanks to every one for the assistance, I HAVE IT WORKING!~!!!

So...are you going to post the whole code? Or perhaps an EXE? Razz

Author:  SNIPERDUDE [ Wed Jan 26, 2011 4:53 pm ]
Post subject:  Re: RE:Turing and "NET" (emails)

ProgrammingFun @ January 26th 2011, 11:36 am wrote:
TokenHerbz @ Wed Jan 26, 2011 9:25 am wrote:
WOW Awesome thanks to every one for the assistance, I HAVE IT WORKING!~!!!

So...are you going to post the whole code? Or perhaps an EXE? Razz


Second.

Author:  copthesaint [ Fri Jan 28, 2011 10:13 am ]
Post subject:  Re: Turing and "NET" (emails)

Im just going to say this now before you decide to post it,
think about all the people who go onto compsci...

now think about all the people who will take your evil code and use it to harras another student sending him 100's of emails a day.

now think of the dude sending the emails geting his account banned on hotmail or gmail *yes they do ban* Then the person comin back here and raging Very Happy

its best that the thing you post for this doesn't work Razz

Believe me when I say this can be an evil tool, facebook + freetime + evil code = nothing good Very Happy

Author:  DemonWasp [ Fri Jan 28, 2011 10:25 am ]
Post subject:  RE:Turing and "NET" (emails)

Any emails sent would be sent from your own gmail / hotmail address. I would hope that would be blindingly obvious.

Anyone with half a brain can already automate sending emails through command-line programs like sendmail anyway. His code manages nothing that a "real" email client couldn't do, save that you can script for it in Turing.

Besides, if your would-be victim can't find a way to deal with hundreds of spam emails coming from a single email address, they don't deserve to use email.

If you think this is exploitable, cop', then just wait until you find out about all the privacy / security issues Facebook has.


: