Send an Email with mIRC (BACK END)

By TheImrac on Mar 05, 2010

**** THIS REQUIRES OPENSSL IF USING SSL SMTP SERVER **** More info here: http://www.mirc.com/ssl.html


Also Note: Have had issues with mIRC 7.1 so please update to the latest

You must modify the server, port, username, and password in the modification section **

Complete Rewrite from Original, it now uses SMTP Authentication and can use SSL.

I have tested this with GMail, it works great, should work with any SSL/Normal SMTP Authentication server.

*** Note on Non-SSL servers, the password is pretty much sent as plain text. If you are not using SSL the traffic can easily be sniffed. Your username and password will be visible, use at your own risk. SSL should be pretty secure.

Also, username and password are stored as plain text. Unfortunately, this is a limitation of mIRC and SMTP

Version Change Log:

V 1.0.0 -- Initial Release (Mar 04, 2010)

V 1.1.0 -- (Aug 12, 2011)

  • Added SSL support
  • Changed to Authentication
  • TESTED WITH GMAIL
  • No need for NSlookup anymore

V 1.2.0 -- (Oct 08,2011)

  • Fixed email.error alias typeo

You can find more about smtp here

Example Below:

; //////////////////////// EXAMPLE  EMAIL   /////////////////////////////////

alias email.test {
  email.start debug

  email.from email@gmail.com my name
  email.to someone@somewhere.com  asd
  email.subject I am testing a new EMAIL sending thingy

  email.body Thank you for signing up with $me on $network $+ . Please msg me with the following command to activate your account!:
  email.body 
  email.body here is the stuff to activate!!

  email.send my_erroralias

}

alias my_erroralias {
  if ($0) echo -b $1-
  else echo -b Mail Sent Complete!
}

; /////////////////////////// END EXAMPLE EMAIL ///////////////////////////////
; +-+-+-+-+-+-+-+-+-+-+-+-+-+
; +  Send Email With mIRC   +
; +  Author: Imrac          +
; +  Version: 1.2.0         +
; +  Date: Oct 8, 2011     +                   
; +-+-+-+-+-+-+-+-+-+-+-+-+-+

;Version Change Log:
/*
V 1.0.0 -- Initial Release (Mar 04, 2010)

V 1.1.0 -- (Aug 12, 2011)

* Added SSL support
* Changed to Authentication
* TESTED WITH GMAIL
* No need for NSlookup anymore

V 1.2.0 -- (Oct 08,2011)

* Fixed email.error alias typeo

*/
; /////////////////////////// USEAGE ///////////////////////////////////
; Step 1: Call /email.start (You may use debug as paramter 1 to display useful info)
; Step 2: Call /email.to/from/subject/body (doesn't matter order, as long as its all their)
; Step 3: Call /email.send (attempts to send the email, you can specify an error alias
;                                it will be called if an error occurs with info )

; Note: Body can be called multiple times with or without content ($crlf is sent if blank)

; /email.start [debug]
; /email.from <email_address> [Real Name]
; /email.to <email_address> [Real Name]
; /email.subject <subject>
; /email.body [your body here] Can be called multiple times
; /email.send [callback]

; callback alias will be blank if success, or return the error.!

; ----------------- MODIFY HERE -------------------------------

alias -l _email.server { return smtp.gmail.com }
alias -l _email.port { return 465 }
alias -l _email.ssl { return $true }
alias -l _email.username { return email@gmail.com }
alias -l _email.password { return xxxxxxxxxx }

; ------------------ END MODIFY -------------------------------

alias email.start {
  if ($hget(email)) { hfree email }
  hadd -m email send_attempt false
  if ($1 == debug) { hadd -m email debug true }
}
alias email.to {
  if ($regex($1,/^(.*?)@(.*?)$/)) {
    hadd -m email to_full $1
    hadd -m email to_host $regml(2)
    hadd -m email to_name $2-
  }
}
alias email.from {
  if ($regex($1,/^(.*?)@(.*?)$/)) {
    hadd -m email from_full $1
    hadd -m email from_host $regml(2)
    hadd -m email from_name $2-
  }
}
alias email.subject { hadd -m email subject $1- }
alias email.body {  hadd -m email body_ $+ $calc($hfind(email,body_*,0,w) + 1) $1- }
alias email.send {
  hadd -m email error $1
  e.connect
  .timeremail 1 10 sockclose S_EMAIL 
}
alias -l e.connect {
  if (!$sock(email)) { sockopen $iif($_email.ssl,-e,) S_EMAIL $_email.server $_email.port }
  else { e.error Socket already in use }
}

alias -l e.write {
  if ($hget(email,debug)) { echo -a C: $iif($1 == -omit, <Omitted Output>, $1-) }
  sockwrite -n S_EMAIL $iif($1 == -omit, $2-, $1-)
}
alias -l e.error { if ($hget(email,error)) $v1 $1- }
alias -l e.finished { if ($hget(email,error)) $v1 }

on *:sockopen:S_EMAIL:{
  if ($sockerr) { e.error Unable to open socket  }
  else {  hadd -m email step 1 }
}

on *:SOCKREAD:S_EMAIL:{
  IF ($sockerr) { e.error Error reading socket }

  var %read 
  var %step $hget(email,step)
  sockread %read

  if ($hget(email,debug)) { echo -a S: %read }

  if ( ($regex(%read,/^(\d\d\d)([ -])(.*)$/)) && ($regml(2) != -) ) {

    var %code $regml(1)
    var %response $regml(3)

    if  ((%step == 1) && (%code == 220)) { e.write EHLO | hinc email step 1 } 
    elseif  ((%step == 2) && (%code == 250)) { e.write AUTH LOGIN | hinc email step 1 }
    elseif  ((%step == 3) && (%code == 334) && (%response == VXNlcm5hbWU6)) { e.write -omit $encode($_email.username,m) | hinc email step 1 }
    elseif  ((%step == 4) && (%code == 334) && (%response == UGFzc3dvcmQ6)) { e.write -omit $encode($_email.password,m) | hinc email step 1 }    
    elseif  ((%step == 5) && (%code == 235)) { e.write MAIL FROM: $+(<,$hget(email,from_full),>) | hinc email step 1  }   
    elseif  ((%step == 6) && (%code == 250)) { e.write RCPT TO: $+(<,$hget(email,to_full),>) | hinc email step 1  }
    elseif  ((%step == 7) && (%code == 250)) { e.write DATA | hinc email step 1 }
    elseif  ((%step == 8) && (%code == 354)) { 
      e.write From: $iif($hget(email,from_name),$qt($v1),) $+(<,$hget(email,from_full),>)
      e.write To: $iif($hget(email,to_name),$qt($v1),) $+(<,$hget(email,to_full),>)
      e.write Subject: $hget(email,subject)
      e.write 
      var %total = $hfind(email,body_*,0,w), %i = 1
      while (%i <= %total) { e.write $hget(email,$+(body_,%i)) | inc %i 1 }
      e.write .
      hinc email step 1
    }
    elseif  ((%step == 9) && (%code == 250)) { e.write QUIT | hinc email step 1 }
    elseif  ((%step == 10) && (%code == 221)) { e.finished }
    else { e.error %read } 
  }
}
on *:SOCKCLOSE:S_EMAIL:{ .timeremail off }
Sign in to comment.
TheImrac   -  Nov 05, 2011

If you follow the link http://www.google.com/support/accounts/bin/answer.py?answer=185833 it will show you how to generate an application specific password. As for attachments, that is beyond the scope of this snippet. I would have to add MIME support, which I am not going to do.

 Respond  
^WeSt   -  Nov 04, 2011

Also why not add and file attachment to this script!

 Respond  
^WeSt   -  Nov 04, 2011

@Thelmrac How can i make it work with the Application-specific password required ?

 Respond  
Nightwatch   -  Oct 08, 2011

I had some issues when running this script on mIRC 7.1 - upgraded to 7.19 and worked like a charm.

Thanks for the help Thelmrac

 Respond  
TheImrac   -  Oct 08, 2011

West, if you follow that link it looks like you may have 2 step verification on your account. You can create a "Application specific" password and will need to generate and use that password for authentication. I will be testing this in a bit.

 Respond  
^WeSt   -  Oct 08, 2011

i have connection problems!, I have edit the _email.username and _email.password with mine and i have fill the correct address to the /email.test alias when i use it these errors appeared!

S: 220 mx.google.com ESMTP n18sm18872351fah.2
C: EHLO
S: 250-mx.google.com at your service, [178.146.104.43]
S: 250-SIZE 35882577
S: 250-8BITMIME
S: 250-AUTH LOGIN PLAIN XOAUTH
S: 250 ENHANCEDSTATUSCODES
C: AUTH LOGIN
S: 334 VXNlcm5hbWU6
C: <Omitted Output>
S: 334 UGFzc3dvcmQ6
C: <Omitted Output>
S: 535-5.7.1 Application-specific password required. Learn more at
S: 535 5.7.1 http://www.google.com/support/accounts/bin/answer.py?answer=185833 n18sm18872351fah.2
535 5.7.1 http://www.google.com/support/accounts/bin/answer.py?answer=185833 n18sm18872351fah.2
 Respond  
TheImrac   -  Oct 07, 2011

irc.ezzychat.com #lobbby

 Respond  
Nightwatch   -  Oct 07, 2011

I cant get it to work. I try gmail and get

read: 220 mx.google.com ESMTP u21sm10361782yhe.1 S: 220 mx.google.com ESMTP u21sm10361782yhe.1 C: EHLO

and try hotmail/live and get ERROR > 421: Unknown command: EMAIL.ERROR

Do you sit on irc anywhere we were can chat about this?

 Respond  
TheImrac   -  Aug 12, 2011

Yeah...... that =P

Finished testing with yahoo and it works!

 Respond  
Jethro   -  Aug 12, 2011

You meant "rewrite" then...nice job.

 Respond  
TheImrac   -  Aug 12, 2011

Alright, complete write of code. Should be much more stable now.

Have fun!!!

 Respond  
cyber   -  Mar 08, 2011

not work some one can fix the code?

 Respond  
kylethegeek   -  Oct 01, 2010

ok

 Respond  
TheImrac   -  Sep 29, 2010

I will take a look at it tonight when I get off of work.

Edit: After looking into using proxies, I am unsure if there is a standard way to do what you wish.

 Respond  
kylethegeek   -  Sep 29, 2010

Any way to use a business class proxy on this? My ip doesn't work D:

 Respond  
kylethegeek   -  Sep 28, 2010

Alright

 Respond  
TheImrac   -  Sep 09, 2010

Make sure to check your spam folder. Should have worked.

 Respond  
kylethegeek   -  Sep 08, 2010

I gotz problem.

step = 2 220 mx.google.com ESMTP 7si1474535ibz.72 step = 3 250 mx.google.com at your service step = 4 250 2.1.0 OK 7si1474535ibz.72 step = 5 250 2.1.5 OK 7si1474535ibz.72 step = 6 354 Go ahead 7si1474535ibz.72 sock sending: From: noreply@mywebsite.com sock sending: To: "their name here" technogeek678@gmail.com sock sending: Subject: some subject to send sock sending Thank you for signing up with iBot on GeekShed. Please msg me with the following command to activate your account!: sock sending sock sending here is the stuff to activate!! step = 7 250 2.0.0 OK 1283991021 7si1474535ibz.72 step = 8 221 2.0.0 closing connection 7si1474535ibz.72 Yeah we finished!!!!

Ok, good, it sent. Right? No, I never got an email. Help?

 Respond  
TheImrac   -  Aug 18, 2010

AndrewFurr: err woops, forgot to add /echo before output in the debug section of step 6. I updated the original post and should have corrected the issue.

As I don't have mIRC installed right now I cannot test the fix. Let me know if there is any more problems.

EDIT: Also, if you are still not receiving an email, check your spam folder. After that, if you are still not receiving an email PM me and we can try to debug why.

The problem with sending emails from a residential IP address, is a lot of times it will be blocked by either the MX server (Mail exchange server) or it could even be blocked by your ISP (thinking you have an infected computer sending out spam).

Shaneny: The script should automagicly do a DNS lookup for a MX server, no setting needed.

 Respond  
AndrewFurr   -  Aug 17, 2010

I really need this snippet to let me know when there is a problem with my rpg bot on a "server computer." I remote desktop in to do my changes to code.

step = 2 220 mx.google.com ESMTP u24si2454458yba.37 step = 3 250 mx.google.com at your service step = 4 250 2.1.0 OK u24si2454458yba.37 step = 5 250 2.1.5 OK u24si2454458yba.37 step = 6 354 Go ahead u24si2454458yba.37 sock sending There seems to be a problem with the bot, please login in to correct issue.

SOCK Unknown command

step = 7 250 2.0.0 OK 1282061371 u24si2454458yba.37 step = 8 221 2.0.0 closing connection u24si2454458yba.37 Yeah we finished!!!!

SOCK Unknown command

SOCK Unknown command

Thats what I received. It looked like it worked, but no email sent?

Of course I see that /sock is an uknown command, what should it be?

Any ideas?

 Respond  
shaneny   -  Jun 17, 2010

Where do I edit the SMTP servers etc.???

 Respond  
TheImrac   -  May 18, 2010

What didn't work? Was it a mirc error or email error (If any)? What email provider did you try and send it to, I know many block emails if they can not find a valid mx (mail exchange) server on your IP address.

 Respond  
kekekeke   -  May 17, 2010

didnt work, maybe im just retarded

 Respond  
TheImrac   -  Mar 13, 2010

Try email.test with your info and set email.start debug so it should look like this:

alias email.test {
  email.start debug

  email.from noreply@mywebsite.com my name here
  email.to someone@gmail.com their name here
  email.subject some subject to send

  email.body Thank you for signing up with $me on $network $+ . Please msg me with the following command to activate your account!:
  email.body 
  email.body here is the stuff to activate!!

  email.send my_erroralias

}
 Respond  
rsb   -  Mar 12, 2010
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.