Author Topic: EMAIL System with AUTH LOGIN and Attachments  (Read 3351 times)

Offline Marmor

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 911
  • 96A285CC
    • View Profile
    • my youtube channel
HI ,

Finally  a working Version for Email with Attachment  and SMTP AUTH LOGIN

use this for Spam and u will  >:D


mime is not mine

modifyed version 0.1
added "<" +">" to from and to$  thx Kanonet

Code: (glbasic) [Select]


//                                              EMAIL SYSTEM for GLB  version  0.002

//               IF U USE THIS  CODE FOR SPAMMING OR MAIL BOMBING YOUR ARE A F.....g B.....d                  !!!!!!!!!!!!!!!!!!!!!!!!!!
//
//               IF YOU WILL SEND A MAIL  GIVE THE USER a HINT BECAUSE HE HAVE NO FLATRATE FOR UMTS OR OTHER  !!!!!!!!!!!!!!!!!!!!!!!!!!


//               This Demo use a full Account from Email Provider  "WEB.DE"
//               You can use this to sending emails from GLB  without having a Freemailer
//

//
//               Create your own Account on web.de /gmx.de/ and other Mailsystems with Auth Login
//
//               Send a PN if you need the password for some Test
//               Thx for the base64 function in the GLB Code Forum
//


//               works with Attachments size from 1 byte up to testet 1,7 MB
//               BEWARE   BASE64 WILL BECOME ARROUND 1,35 x Filesize                                                 
//               Big files become much bigger  Sizes !!!
//   











GLOBAL file$="d:/decorator.exe"                  // u need a file for the attachment
GLOBAL sendfile$="dec.exe"                    // attachment name shows  in the mail
GLOBAL size#


size# =GETFILESIZE (file$)





//---------------------------------------------------------------------------------------------------------------------

GLOBAL      to$     =    "powerasm1xyz@gmx.de"                               // Put your own Email ADDY here !!!!!!!!!
GLOBAL      mode    =      1                          // 1 Shows the Serverreply if DEBUGMODE ON
GLOBAL      delay   =     100                                           // Test your own (100 ms run on the most Devices)
GLOBAL      subj$    =   "MAIL from MYGAME Vers: 0.9a "                 // Subject
GLOBAL      mess1$   =   "GLB GAME STARTET at :" +PLATFORMINFO$("time") // Messagestrings
GLOBAL      mess2$   =   "PLATFORM :"+PLATFORMINFO$("")                 //
GLOBAL      mess3$   =   "DEVICE   :"+PLATFORMINFO$("DEVICE")           //
GLOBAL      mess4$   =   "ID       :"+PLATFORMINFO$("ID")               //
GLOBAL      mess5$   =   "Locale   :"+PLATFORMINFO$("LOCALE")           // last  Message



//--------------------------- dont touch this -------------------------------------------------------------------------



GLOBAL      port    =     25                                            // Standard smtp port
GLOBAL      server$ =    "smtp.web.de"                                  // Serveradresse for web.de
GLOBAL      from$   =    "onlyforglb@web.de"                            // EMAIL ADRESS  dont change it !!!!!!!!!
GLOBAL      pass$   =    "coolpassword"                               // Password for Email ADRESS
GLOBAL      LFCR$   =  CHR$(13)+CHR$(10)                                //  0dh +0ah
GLOBAL      socket%                                                     // Socketnumber from TCPCONNECT
GLOBAL       reply$                                                     // needed for the famouse base64encode$ function (THX)

GLOBAL      from64$ = Base64_encode$(from$)                             // we need base64 from sender
GLOBAL      pass64$ = Base64_encode$(pass$)                             // we need base64 from password
GLOBAL      testsize
GLOBAL      zas
GLOBAL      zar   

   
testsize = 90            // this defines the lenght for the sending string  in the attachment  , 90 is the best for not become the "LINE TOO LONG " Error from the provider

                     //
zas  = INTEGER (size#/testsize)   // how offten is 90 in filesize ?
zar  =  MOD (size#,testsize)      // the rest , booth needed for the base64 attachment





//---------------------------------------------------------------------------------------------------------------------

 

IF SOCK_INIT()=FALSE THEN END                                       // ups

           socket% = SOCK_TCPCONNECT(server$,port)




IF socket%<> -1                                                  // start sending !! BEWARE the correct Order

        SOCK_TCPSEND (socket%, "HELO GLB MAILSYSTEM 0.1 "+LFCR$)
        check()
            SOCK_TCPSEND (socket%, "AUTH LOGIN"+LFCR$)
            check()
            SOCK_TCPSEND (socket%,  from64$+LFCR$)
            check()
            SOCK_TCPSEND (socket%,  pass64$+LFCR$)
            check()
            SOCK_TCPSEND (socket%, "MAIL FROM:<"+from$ +">"+LFCR$)
            check()
            SOCK_TCPSEND (socket%, "RCPT TO:<"+to$  +">"  +LFCR$)
            check()
            SOCK_TCPSEND (socket%, "DATA"+LFCR$)
            SOCK_TCPSEND (socket%, "Subject: "+subj$ +LFCR$)
            check()
            SOCK_TCPSEND (socket%, "X-MAILER:GLB MAIL SYSTEM"+LFCR$)
            check()
            SOCK_TCPSEND (socket%, "X-MSMail-Priority: 1"+LFCR$)
            check()
            SOCK_TCPSEND (socket%, "MIME-Version: 1.0" +LFCR$ )
            check()
            SOCK_TCPSEND (socket%, "Content-Type: multipart/mixed; boundary= --_--=123" +LFCR$)   // mybound ="--_--=123"   !!!
            check()
            SOCK_TCPSEND (socket%, ""+LFCR$)
            check()
            SOCK_TCPSEND (socket%, "--" + "--_--=123"+LFCR$)                                     // startboundary !  add "--" before !                                   
            check()
            SOCK_TCPSEND (socket%, "Content-TYPE: text/plain; charset=us-ascii" +LFCR$)
            check()
            SOCK_TCPSEND (socket%, "Content-Transfer-Encoding: 7bit"+LFCR$)                     // some TEXT is coming
            check()
            SOCK_TCPSEND (socket%, ""+LFCR$)                                                   // start/stop HEADER
   
           

            SOCK_TCPSEND (socket%,  "START OF MESSAGE"+LFCR$)                                   // email plain text

    SOCK_TCPSEND (socket%,  " "+LFCR$)
    SOCK_TCPSEND (socket%,  " "+LFCR$)
    SOCK_TCPSEND (socket%,  " "+LFCR$)
    SOCK_TCPSEND (socket%,   mess1$+ LFCR$)
    SOCK_TCPSEND (socket%,   mess2$+ LFCR$)
    SOCK_TCPSEND (socket%,   mess3$+ LFCR$)
    SOCK_TCPSEND (socket%,   mess4$+ LFCR$)
    SOCK_TCPSEND (socket%,   mess5$+ LFCR$)
    SOCK_TCPSEND (socket%,  " "+LFCR$)
    SOCK_TCPSEND (socket%,  " "+LFCR$)
    SOCK_TCPSEND (socket%,  " "+LFCR$)
    SOCK_TCPSEND (socket%,  "END OF MESSAGE "  +  LFCR$)
            SOCK_TCPSEND (socket%,  "" +LFCR$)
           
           
           
           
         
            SOCK_TCPSEND (socket%, "--"+"--_--=123"+LFCR$)                                             //nextboundary  also add "--" before !!
            SOCK_TCPSEND (socket%, "Content-Type: application/octet-stream; name="+sendfile$ +LFCR$)  // Filename !!
            SOCK_TCPSEND (socket%,  "Content-Transfer-Encoding: base64"+LFCR$)                       // a base64 encoded file is coming   !!
            SOCK_TCPSEND (socket%, ""+LFCR$)                                                        // start /stop HEADER
           

           
// ---  open the file and call the base64 routine    ok i know its better to decode before you call sendmail

            OPENFILE  (1,file$,TRUE)



          FOR r = 1 TO zas                    // remember zas from above ?
       

            READSTR 1, read$, testsize
            read64$ = Base64_encode$(read$)   
            SOCK_TCPSEND (socket%,read64$  +LFCR$)
          NEXT

            READSTR 1, read$, zar             // also zar ??
            read64$ = Base64_encode$(read$)
            SOCK_TCPSEND (socket%,read64$+LFCR$)
            SOCK_TCPSEND (socket%,""+LFCR$ )
           
           CLOSEFILE 1
           
//-------------------------------------------------------------------------------------- end of bad implement ------



      SOCK_TCPSEND (socket%, "--"+"--_--=123" +" --"+LFCR$)                                   //  ENDBOUNDARY !!  add "--" before and after the boundary$    !!
            check()
    SOCK_TCPSEND (socket%,  " "+LFCR$)
    check()
    SOCK_TCPSEND (socket%, "."+LFCR$)                                                // SEND "." as End Marker
    check()
    SOCK_TCPSEND (socket%, "QUIT"+LFCR$)
    check()
    SOCK_CLOSE   (socket%)                                                      //WOOOOT
        ENDIF


END



// GENIUS BASE64 Function
FUNCTION Base64_encode$:source$




LOCAL result$, group$
LOCAL t, n, i, u, ant, pad
LOCAL Base64$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" // Normal


FOR n = 0 TO LEN(source$)-1 STEP 3
t = 0 // temp holder of the three bytes
ant = 3
FOR i = 0 TO 2
u = 0
IF n+i > LEN(source$)-1 // Do we have enough characters left?
DEC ant, 1 // No, remove one byte from result
ELSE
u = ASC(MID$(source$, n+i, 1)) // yes, add it
ENDIF
t = (t*0x100) + u // shift left and add character to temp-group
NEXT
pad = 3-ant // How many characters padding?
group$ = ""
FOR i = 0 TO 3
u = bAND(t, 0x3F) // Single out the bottom 6 bits
t = t / 0x40 // shift right by 6 bits
IF pad > 0
// IF url = FALSE

group$ = "=" + group$ // add padding
// ELSE // or skip if we are encoding for an url
// ENDIF
DEC pad, 1
ELSE
group$ = MID$(Base64$, u, 1) + group$ // add to encoded temp-group
ENDIF
NEXT
result$ = result$ + group$ // add temp-group to final result
NEXT


RETURN result$
ENDFUNCTION



// SIMPLE DELAY and DEBUG Function
FUNCTION check:

SLEEP delay

    IF mode =1
    LOCAL rv% = SOCK_RECV(socket%, reply$, 1024)
        DEBUG  "Recv: " + rv% +" : " +reply$+"\n"
    ENDIF

ENDFUNCTION


« Last Edit: 2012-Jan-06 by Marmor »

Offline Nathan

  • Mr. Polyvector
  • ***
  • Posts: 116
    • View Profile
Superb work!  Don't use for spam, LOL.

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3366
  • Integrated Brain
    • View Profile
Very Cool!!!  :nw: :nw: :nw:

Only advice for 1and1 Service works too, very fine!!! THXKS   :good: :good:

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
I had problems getting this to work with yahoo mail servers, so i fixed all issues that i could find. Now it works with Yahoo and should work with the others too. And i packed everything together into one Type so it is encapsulated and can easily get integrated in your projects.
Can some of you please test this with your email providers? Thank you.

Code: (glbasic) [Select]
//                                               EMAIL SYSTEM FOR GLB  version  0.003
//
// IF U USE this  CODE FOR SPAMMING OR MAIL BOMBING YOUR ARE A F.....g B.....d                  !!!!!!!!!!!!!!!!!!!!!!!!!!
//
// IF YOU WILL SEND A MAIL  GIVE THE USER a HINT BECAUSE HE HAVE NO FLATRATE FOR UMTS OR OTHER  !!!!!!!!!!!!!!!!!!!!!!!!!!
//
// Create your own Account on web.de /gmx.de/ or other Mailsystems with Auth Login
// Always remember: your accountname/ password is NOT encrypted, the user of your app, or "a man in the middle" will be able to sniff it! Base64 is no encryption!
//
// works with Attachments size from 1 byte up to testet 2 MB
// BEWARE   BASE64 WILL BECOME ARROUND 1,36 x Filesize
// Big files become much bigger  Sizes !!!
//
// Autors: MrTAToad, ampos, Marmor, kanonet
//
// Thanks Moru for the base64 function



// prepare mail
LOCAL mail AS TMail
mail.SetServer( "smtp.mail.yahoo.de", 25, "youremail@yahoo.de", "yourpassword")
mail.AddReceiver("receiver@samble.com")
mail.AddReceiver("bcc@sample.com", TRUE)
mail.AddText("hi")
mail.AddText("this is a test!")
mail.AddText("äöüßéè\nÄÖÜÉÈ @€µ|²³")
mail.AddAttachment("../icon.png")
mail.AddAttachment("Email.exe")
// finally send the mail
mail.SendMail("test mail")

END



TYPE TMail
server$
port%
socket%
delay%
password$
from$
to$[]
bcc$[]
attachment[] AS TMailAttachment
text$
fakefrom$
fakedate$ // must use the format "04 Jan 2012 13:11:50 +0200"

FUNCTION SetServer: server$, port%, from$, password$
self.server$ = server$
self.port% = port
self.from$ = from$
self.password$ = Base64_encode$( password$ )
ENDFUNCTION

FUNCTION AddText: newtext$
self.text$ = self.text$ + newtext$ + "\n"
ENDFUNCTION

FUNCTION AddAttachment: filename$
IF DOESFILEEXIST( filename$ )
LOCAL t AS TMailAttachment, filesize%, zas%, read$
LOCAL testsize% = 740 // this defines the lenght for the sending string in the attachment, 90 is the best for not getting the "LINE TOO LONG " Error from the provider

t.file$ = MID$( filename$, REVINSTR( REPLACE$( filename$, CHR$(92), "/" ), "/", -1 )+1, -1 )
filesize = GETFILESIZE( filename$ )
zas = INTEGER( filesize/testsize ) // how often is testsize% in filesize% ?

OPENFILE( 1, filename$, TRUE )

LOCAL file$ = ""
FOR i = 1 TO zas
READSTR 1, read$, testsize
DIMPUSH t.bin$[], Base64_encode$(read$)
NEXT

            READSTR 1, read$, MOD( filesize, testsize )
            DIMPUSH t.bin$[], Base64_encode$(read$)

CLOSEFILE 1

DIMPUSH self.attachment[], t
ELSE
DEBUG "File '"+filename$+"' does not exist.\n"
ENDIF
ENDFUNCTION

FUNCTION AddReceiver: to$, blind%=FALSE
IF blind
DIMPUSH self.bcc$[], to$
ELSE
DIMPUSH self.to$[], to$
ENDIF
ENDFUNCTION

FUNCTION SendMail: subject$

LOCAL filesattached%, from64$, text$[]

// important variables, you may need to change this
self.delay% = 100 // Test your own (100 ms run on the most Devices), keep it as low as possible
LOCAL boundary$ = "5.g_Boundary=_TaTo05+Mar40*kaN5sLMZ" // should only contain ascii chars and should not be in your text!

// prepare data
from64$ = Base64_encode$( self.from$ )
IF self.fakefrom$="" THEN self.fakefrom$ = self.from$
SPLITSTR( REPLACE$( REPLACE$( self.text$, "\r\n", "\n" ), "\r", "\n" ), text$[], "\n", FALSE ) // split text in individual lines...
IF LEN( self.attachment[] ) THEN filesattached = TRUE

// connect to server
IF SOCK_INIT()=FALSE THEN END // error
self.socket = SOCK_TCPCONNECT( self.server$, self.port )
IF self.socket = -1 THEN END // error

// start header
self.intern_send_line( "HELO GLB MAILSYSTEM 0.3" )
self.intern_send_line( "AUTH LOGIN" )
self.intern_send_line(  from64$ )
self.intern_send_line(  self.password$ )
self.intern_send_line( "MAIL FROM:<"+self.from$+">" )
FOREACH to$ IN self.to$[] // send to all receivers
self.intern_send_line( "RCPT TO:<"+to$+">" )
NEXT
FOREACH to$ IN self.bcc$[] // send all blind copies
self.intern_send_line( "RCPT TO:<"+to$+">" )
NEXT
self.intern_send_line( "DATA" )

// start body
self.intern_send_line( "From: <"+self.fakefrom$+">" )
FOREACH to$ IN self.to$[]
self.intern_send_line( "To: <"+to$+">" )
NEXT
self.intern_send_line( "Subject: "+subject$ )
IF self.fakedate$<>"" THEN self.intern_send_line( "Date: "+self.fakedate$ )

// prepare MIME
self.intern_send_line( "MIME-Version: 1.0" )
IF filesattached
self.intern_send_line( "Content-Type: Multipart/Mixed; boundary="+CHR$(34)+boundary$+CHR$(34) )
self.intern_send_line( "" )
self.intern_send_line( "--"+boundary$ )
ENDIF

// send text
IF self.text$<>""
self.intern_send_line( "Content-Type: text/plain; charset="+CHR$(34)+"iso-8859-15" )
self.intern_send_line( "Content-Transfer-Encoding: 8bit" )
self.intern_send_line( "Content-Disposition: inline" )
self.intern_send_line( "" )
FOREACH t$ IN text$[]
SOCK_TCPSEND( self.socket, t$ + "\r\n" )
SLEEP 15
NEXT
self.intern_send_line( "" )
ENDIF

// send attachments
FOREACH a IN self.attachment[]
self.intern_send_line( "--"+boundary$ )
self.intern_send_line( "Content-Type: application/octet-stream; name="+CHR$(34)+a.file$+CHR$(34) )
self.intern_send_line( "Content-Transfer-Encoding: base64" )
self.intern_send_line( "Content-Disposition: attachment" )
self.intern_send_line( "" )
FOREACH line$ IN a.bin$[]
SOCK_TCPSEND( self.socket, line$ + "\r\n" )
SLEEP 15
NEXT
self.intern_send_line( "" )
NEXT

IF filesattached THEN self.intern_send_line( "--"+boundary$+"--" )

// end mail
self.intern_send_line( "." ) // SEND "." as end Marker
self.intern_send_line( "QUIT" )
SOCK_CLOSE( self.socket ) // all was done

// clear/delete all mail data
DIM self.to$[0]
DIM self.bcc$[0]
DIM self.attachment[0]
self.text$ = ""
ENDFUNCTION

FUNCTION intern_send_line: text$
SOCK_TCPSEND( self.socket, text$ + "\r\n" )
SLEEP self.delay

LOCAL reply$, rv% = SOCK_RECV( self.socket, reply$, 1024 )
DEBUG  "Recv: " + rv% +" : " +reply$+"\n"
ENDFUNCTION

ENDTYPE

TYPE TMailAttachment
file$
bin$[]
ENDTYPE


// GENIUS BASE64 Function
FUNCTION Base64_encode$: source$

LOCAL result$, group$, lensource%=LEN(source$)-1
LOCAL t%, u%, ant%, pad%
LOCAL Base64$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" // Normal

FOR n = 0 TO lensource STEP 3
t = 0 // temp holder of the three bytes
ant = 3
FOR i = 0 TO 2
u = 0
IF n+i > lensource // Do we have enough characters left?
DEC ant, 1 // No, remove one byte from result
ELSE
u = ASC(source$, n+i) // yes, add it
ENDIF
t = ASL(t, 8) + u // shift left and add character to temp-group
NEXT
pad = 3-ant // How many characters padding?
group$ = ""
FOR i = 0 TO 3
u = bAND(t, 0x3F) // Single out the bottom 6 bits
t = ASR(t, 6) // shift right by 6 bits
IF pad > 0
// IF url = FALSE
group$ = "=" + group$ // add padding
// ELSE // or skip if we are encoding for an url
// ENDIF
DEC pad, 1
ELSE
group$ = MID$(Base64$, u, 1) + group$ // add to encoded temp-group
ENDIF
NEXT
result$ = result$ + group$ // add temp-group to final result
NEXT

RETURN result$
ENDFUNCTION

You always find the latest version on my website: http://www.kanonet.de/downloads/email
« Last Edit: 2012-Oct-04 by kanonet »
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1783
    • View Profile
    • Homepage
I seriously hope you don't plan on using this to send emails from your applications out in the wild? It's way too easy to snoop the password of your account and it will be used for spamming. With your name on it :-)

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Your right, thats why i have this line at the beginning:
Code: (glbasic) [Select]
// Always remember: your accountname/ password is NOT encrypted, the user of your app, or "a man in the middle" will be able to sniff it! Base64 is no encryption!
Would be cool if Gernot would give us SSL or something like that.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1783
    • View Profile
    • Homepage
Open up your program in a hexeditor and search for your password and then cry some more :-)

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
LOL its your own fault if store your password in such a easy way, you should at least try to make it harder. But of cause it doesnt matter how you store it, there always maybe a way to crack and read it.
And dont forget all data will be send non-ecrypted (base64 is no encryption!), including the password. So everyone will be able to read it, thats why we would need SSL.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 930
  • KodeSource
    • View Profile
    • KodeSource
I'm no security expert, but how safe would it be to send the 'email' to a server of yours running a php script.
Then have that script relay the email to the destined recipient from the server.
That way your account name and password are stored only on your server.

Other than that, I like how you converted it to a type with functions, it really encapsulates the code!
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]