EmiaCtrlLite | Emia4Win | DecMsgX | DecMime

EmiaCtrlLite (EMIACtrlLite.dll)Documentation 20030718 | Back

 

Description:

EmiaCtrlLite is Free-Standing Bare-Bone COM DLL(Dynamic Link Library) POP3/SMTP object for sending and retrieving electronic mail. It can be used as an Object with the intent to give Web/Internet Applications, Email Capabilities. It can be incorporated into any application, if it's language support's Win32 OLE. EmiaCtrlLite differs from Emia4Win, as Emia4Win runs as a process for each transaction, EmiaCtrlLite runs in light-weight processes known as threads. Therefore, EmiaCtrlLite, is suited for larger scale web-mail systems, where performance and robustness really matters.

 

COPYRIGHT
EmiaCtrlLite (c) 2003 Jeremy Aiyadurai. All Rights Reserved. EmiaCtrlLite is free software in the sense that you are free to download, copy and redistribute it, provided that the copyright notice is retained in the copy. You are not allowed to charge a fee for the software without the consent of the author other than that to cover the cost of the distribution. If a fee is charged it must be made clear to the purchaser that the software is freeware and that the fee is to cover the distributor's costs of providing the software.
DISCLAIMER
TheEmiaCtrlLite software is provided as is without any warranty of any kind. The entire risk arising out of the use or performance of this product and documentation remains with recipient. To the maximum extent permitted by applicable law, in no event shall program EmiaCtrlLite or its suppliers be liable for any consequential, incidental, direct, indirect, special, punitive, recursive, or other damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, personal injury, disruption of family life, or other pecuniary loss) arising out of this agreement or the use of or inability to use the product EmiaCtrlLite.

 

TOC

[TOP]EmiaCtrlLite Overview

EmiaCtrlLite PROGID = "EmiaLITE.SendRetrieve"
To install, in the directory that EMIACtrlLite.dll is, type "regsvr32 emiactrllite.dll".

METHODS for SMTP (Sending Mail)

  • VT_NULL set_SMTP( VT_BSTR smtphost , VT_I4 port )
  • VT_VARIANT send_mail(VT_BSTR RecipientAddress, VTBSTR SenderAddress, VT_BSTR message )

send_mail returns "1" on successful send, and "0" on failure.

METHODS for POP3 (Retrieving,Checking and Deleting Mail)

  • VT_NULL set_POP3( VT_BSTR pop3host, VT_I4 port, VT_BSTR userid, VT_BSTR password )
  • VT_VARIANT get_stat()
  • Note: get_stat closes connection. you will have to recreate object, if using any method after.

  • VT_VARIANT get_list()
  • VT_VARIANT get_message( VT_I4 msgnum,VT_I2 DELSWITCH*)

* DELSWITCH = 1 or 0, (1= delete message on server, 0 = keep message on server)

  • VT_VARIANT del_remote_msg(VT_BSTR msgnum* )

del_remote_msg returns "1" on successful deletion and "0" on unsuccessful Deletion
* msgnum ( a string eg. to delete message 1 from server ="1", or string keyword to remove all message on server="all"

[TOP] (Trouble Shooting)\Debugging


  • Can EmiaCtrlLite be used with any language?

EmiaCtrlLite will work well with any language where there is support for Win32 OLE or accessing COM objects.

  • How is it that when I try to retrieve,decode or check mail, EmiaCtrlLite hangs?
The problem can be caused by Antivirus Software which may be monitoring your pop3 port to check incoming messages for for viruses. If you have McAfee or Nortons Antivirus, disable email monitoring.
This problem can also be caused by certian firewall products.
  • ...regarding retrieving a message from the server - is there anyway to control what headers are shown?
The original intentions were to let the developer pick and choose the headers. You can do this with the help of Regex's (Regular Expressions) to parse the message, in order to control what headers the user may view. If you are using VB-Script, you can visit MSDN, where I found information about using Regular Expressions with VB-Script
here is the link:

http://msdn.microsoft.com/library/default.asp?URL=/library/en-us/dnclinic/html/scripting051099.asp
  • ..what does does it mean by messages such as "Connection Failed! blah blah...(method_name_here())"?

These are error messages. You may have initialized set_POP3 with invalid perameters. You may have also supplied *method_name_here() with invalid perameters.The outcome of this would mean a failed connection ( transaction) to the server. If all seems correct, then, the error would mean, "zero messages (on server)" or "message (#) does not exist!".
*method_name_here() could be one of the following:
get_stat, get_list or get_message

 


[TOP] EmiaCtrlLite version History

version 20030317
-first release
version 20030618
- added improved error notification!
- fixed minor bugs, should no longer hang
version 20030717
-SOAP enabled, web service ready!
version 20030718
- web service security enhancement
version 20030805
- IMPORTANT: improved web service security enhancement

version 9.8.20.0 -IMPORTANT: some compatibility issues resolved

[TOP]Sending Mail via VBScript

[TOP]

example code snippet



send message


<%
dim Emia,newline,message,recipient,sender,smtphost,smtpport
newline = chr(13)
recipient = "her@work.net"
sender = "him@home.net"
smtphost = "mail.home.net"
smtpport = 25
message = "hello all, this is a test"&newline&"Hello World! blablablblah"
Set Emia = Server.CreateObject("EmiaLITE.SendRetrieve")
Emia.set_SMTP smtphost,smtpport
Emia.send_mail recipient,sender,message
%>

[TOP]Checking Mail via VBScript/ASP

Check Mail example



pop3 list



<%
dim mailserver,port,id,pass,mailer,list
mailserver = "mail.host.com"
port = 110
id = "usrname"
pass = "*****************"
Set mailer = Server.CreateObject("EmiaLITE.SendRetrieve")
mailer.set_POP3 mailserver,port,id,pass
list = mailer.get_list
'use Regular Expressions to search and replace "<" with "<" and ">" with ">"
dim r1,r2
Set r1 = new regexp
r1.Pattern = "<"
Set r2 = new regexp
r2.Pattern = ">"
for each line in list
dim dataline
if r1.Test(line.From) = true then
line.From = r1.Replace(line.From,"<")
end if
if r2.Test(line.From) = true then
line.From = r2.Replace(line.From,">")
end if

dataline = line.From+"||"+line.Subject+"||"+line.Size+"||"+line.Number+"||"+line.Date+"||"+line.Attach
Response.Write("

")
dim data
data = split(dataline,"||")
for each piece in data
Response.Write("
")
next
Response.Write("
")
next
%>
"+piece+"


[TOP]Retrieving Mail via VBScript/ASP

Retrieve a Message example



pop3 retrieve message


<%
dim mailserver,port,id,pass,mailer,message
mailserver = "mail.host.com"
port = 110
id = "jondoe"
pass = "nobiz"
Set mailer = Server.CreateObject("EmiaLITE.SendRetrieve")
mailer.set_POP3 mailserver,port,id,pass
message = mailer.get_message(1,0)

for each line in message
Response.Write("
"+line)
next
%>



[TOP]Deletion of Mail while retrieving it off server via VBScript

Deletion example



pop3 list


<%
dim mailserver,port,id,pass,mailer,message
mailserver = "mail.host.com"
port = 110
id = "jondoe"
pass = "nobiz"
Set mailer = Server.CreateObject("EmiaLITE.SendRetrieve")
mailer.set_POP3 mailserver,port,id,pass
message = mailer.get_message(1,1) ' 1 = delete message # 1 from server.

for each line in message
Response.Write("
"+line)
next
%>



[TOP]Explicitly delete Mail off server via VBScript

Deletion example



pop3 delete


<%
dim mailserver,port,id,pass,mailer,message
mailserver = "mail.host.com"
port = 110
id = "jondoe"
pass = "nobiz"
Set mailer = Server.CreateObject("EmiaLITE.SendRetrieve")
mailer.set_POP3 mailserver,port,id,pass
mailer.del_remote_msg("1") ' a "#" or "all"
%>

 

[TOP]Explicitly Check the mail box STAT via VBScript

check the stat example



pop3 stat


<%

dim mailserver,port,id,pass,mailer,stat
mailserver = "mail.host.com"
port = 110
id = "jondoe"
pass = "nobiz"
Set mailer = Server.CreateObject("EmiaLITE.SendRetrieve")
mailer.set_POP3 mailserver,port,id,pass
Set stat = mailer.get_stat
Response.Write(stat.MessageCount+"||"+stat.BoxSize+"
")
%>

[TOP]EmiaCtrlLite as a Web Service for the distributed enviroment

EmiaCtrlLite version 20030717 and later, can now be easily installed as a web service. We have provided a provided a simple utility to make your migration as simple as possible.
To host this web service, the host must meet the following requirements:

  • Microsoft Windows 2000 Professional (service pack 2) or later
  • IIS (Internet Information Server) 5.0 or later
  • WSH (Windows Scripting Host)
  • Microsoft .Net Framework 1.0 (with ASP.NET) or later

The utility to install this web service, installews.exe will place a wrapper around the EmiaCtrlLite.dll, named EmiaWebServiceLite.asmx. We will be providing documentation, on how to manually install this service for advanced configurations, in the future.

EmiaWebServiceLite.asmx has the following methods:

SECURE METHODS for POP3

  • VT_VARIANT get_stat_e(VT_BSTR pop3host, VT_I4 port, VT_BSTR userid, VT_BSTR password)
  • VT_VARIANT get_list_e(VT_BSTR pop3host, VT_I4 port, VT_BSTR userid, VT_BSTR password)
  • VT_VARIANT get_message_e( VT_BSTR pop3host, VT_I4 port, VT_BSTR userid, VT_BSTR password, VT_I4 msgnum, VT_I2 DELSWITCH*)

* DELSWITCH = 1 or 0, (1= delete message on server, 0 = keep message on server)

  • VT_VARIANT del_remote_msg_e(VT_BSTR pop3host, VT_I4 port, VT_BSTR userid, VT_BSTR password, VT_BSTR msgnum* )

METHODS for SMTP (Sending Mail)

  • VT_VARIANT send_mail(VT_BSTR smtphost , VT_I4 port,(VT_BSTR RecipientAddress, VTBSTR SenderAddress, VT_BSTR message )

METHODS for POP3 (Retrieving,Checking and Deleting Mail)

  • VT_VARIANT get_stat(VT_BSTR pop3host, VT_I4 port, VT_BSTR userid, VT_BSTR password)
  • VT_VARIANT get_list(VT_BSTR pop3host, VT_I4 port, VT_BSTR userid, VT_BSTR password)
  • VT_VARIANT get_message( VT_BSTR pop3host, VT_I4 port, VT_BSTR userid, VT_BSTR password, VT_I4 msgnum, VT_I2 DELSWITCH*)

* DELSWITCH = 1 or 0, (1= delete message on server, 0 = keep message on server)

  • VT_VARIANT del_remote_msg(VT_BSTR pop3host, VT_I4 port, VT_BSTR userid, VT_BSTR password, VT_BSTR msgnum* )

 


* msgnum ( a string eg. to delete message 1 from server ="1", or string keyword to remove all message on server="all"

Developing Clients for "EmiaWebServiceLite.asmx"

For the Client, you must install "Microsoft SOAP Toolkit". It is recommended that the client should use the "secure methods", to avoid sending passwords as clear text in soap messages. To use the secure methods, you must first encrypt your POP3 password using RC4 encryption, then convert it to BASE64 for transmission.All methods return "Strings", so it is up to the developer to parse the data from the String. An example is given below:

Dim mail
Dim sbox(255)
Dim key(255)
Set mail = CreateObject("MSSOAP.SOAPClient")
mail.ClientProperty("ServerHTTPRequest") = True
Call mail.mssoapinit("http://127.0.0.1:8080/emiawebservicelite/emiawebservicelite.asmx?wsdl","","","")
dim password
dim keyw
keyw = TimeKey(now)
WScript.Echo keyw
password = EnDeCrypt("pwd",keyw)
password = Base64Encode(password)
mail.send_mail "mail.host.com",25,"test1@host.com","test2@host.com","test from webservice"
Dim message
message = CStr(message)
message = mail.get_message_e("mail.host.com",110,"userid",password,1,0)
WScript.Echo message
dim stat
stat = CStr(stat)
stat = mail.get_stat_e("mail.host.com",110,"userid",password)
WScript.Echo stat
list = mail.get_list_e("mail.host.com",110,"userid",password)
WScript.Echo list

-------------------------------------------------------------------------------------------------------------------------------------


function TimeKey(currTime)
TimeKey = FormatUTC(currTime)
dim keyarry
keyarry = split(TimeKey,":")
TimeKey = keyarry(0)+":"+keyarry(1)
end function


Sub RC4Initialize(strPwd)
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: This routine called by EnDeCrypt function. Initializes the :::
'::: sbox and the key array) :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

dim tempSwap
dim a
dim b

intLength = len(strPwd)
For a = 0 To 255
key(a) = asc(mid(strpwd, (a mod intLength)+1, 1))
sbox(a) = a
next

b = 0
For a = 0 To 255
b = (b + sbox(a) + key(a)) Mod 256
tempSwap = sbox(a)
sbox(a) = sbox(b)
sbox(b) = tempSwap
Next

End Sub

Function EnDeCrypt(plaintxt, psw)
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: This routine does all the work. Call it both to ENcrypt :::
'::: and to DEcrypt your data. :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

dim temp
dim a
dim i
dim j
dim k
dim cipherby
dim cipher

i = 0
j = 0

RC4Initialize psw

For a = 1 To Len(plaintxt)
i = (i + 1) Mod 256
j = (j + sbox(i)) Mod 256
temp = sbox(i)
sbox(i) = sbox(j)
sbox(j) = temp

k = sbox((sbox(i) + sbox(j)) Mod 256)

cipherby = Asc(Mid(plaintxt, a, 1)) Xor k
cipher = cipher & Chr(cipherby)
Next

EnDeCrypt = cipher

End Function



Function Base64Encode(inData)
'rfc1521
'2001 Antonin Foller, PSTRUH Software, http://pstruh.cz
Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim cOut, sOut, I

'For each group of 3 bytes
For I = 1 To Len(inData) Step 3
Dim nGroup, pOut, sGroup

'Create one long from this 3 bytes.
nGroup = &H10000 * Asc(Mid(inData, I, 1)) + _
&H100 * MyASC(Mid(inData, I + 1, 1)) + MyASC(Mid(inData, I + 2, 1))

'Oct splits the long To 8 groups with 3 bits
nGroup = Oct(nGroup)

'Add leading zeros
nGroup = String(8 - Len(nGroup), "0") & nGroup

'Convert To base64
pOut = Mid(Base64, CLng("&o" & Mid(nGroup, 1, 2)) + 1, 1) + _
Mid(Base64, CLng("&o" & Mid(nGroup, 3, 2)) + 1, 1) + _
Mid(Base64, CLng("&o" & Mid(nGroup, 5, 2)) + 1, 1) + _
Mid(Base64, CLng("&o" & Mid(nGroup, 7, 2)) + 1, 1)

'Add the part To OutPut string
sOut = sOut + pOut

'Add a new line For Each 76 chars In dest (76*3/4 = 57)
'If (I + 2) Mod 57 = 0 Then sOut = sOut + vbCrLf
Next
Select Case Len(inData) Mod 3
Case 1: '8 bit final
sOut = Left(sOut, Len(sOut) - 2) + "=="
Case 2: '16 bit final
sOut = Left(sOut, Len(sOut) - 1) + "="
End Select
Base64Encode = sOut
End Function

Function MyASC(OneChar)
If OneChar = "" Then MyASC = 0 Else MyASC = Asc(OneChar)
End Function


function FormatUTC(ByVal vDate)
'================================================
'Converts input date/time to Universal Time
'Coordinate (UTC) in the same format as JScript's
'Date().toUTCString() method.
'
' dayabbreviation, dd monthname yy hh:mm:ss UTC
'
'Example: Fri, 2 July 1999 18:17:50 UTC
'
'================================================
if isdate(vdate) then
vdate = cdate(vdate)
else
err.raise &h7001,"FormatUTC","Argument is not a valid date"
end if

set shell = createobject("wscript.shell")

'ActiveTimeBias is the number of minutes that UTC
'is offset from local time. It is added to local
'date/time to get UTC equivalent.
'
strValueName = _
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\"_
& "TimeZoneInformation\ActiveTimeBias"
tmpTimeOffset = shell.regread(strValueName)

'ActiveTimeBias can be REG_BINARY or REG_DWORD
'depending on the OS version...
'
if IsArray(tmpTimeOffset) then
'it's REG_BINARY w/ 2 bytes significant
lngTimeOffset = tmpTimeOffset(0) + (tmpTimeOffset(1)*(2^8))
else
'it's REG_DWORD
lngTimeOffset = tmpTimeOffset
end if
dt = DateAdd("n", lngTimeOffset, vDate)

'Extract the "fields" of the date/time and
'reformat into UTC standard format.
'
dayabbr = weekdayname(weekday(dt),True) 'abbreviated

'JScript doesn't include leading 0 on day,
'so we don't either.
'
dd = datepart("d",dt)
monnm = monthname(month(dt),true)
yyyy = year(dt)

hh = right("00" & hour(dt),2)
mn = right("00" & minute(dt),2)
ss = right("00" & second(dt),2)

FormatUTC = _
dayabbr & ", " _
& dd & " " & monnm & " " & yyyy & " " _
& hh & ":" & mn & ":" & ss _
& " UTC"

end function

 


 

 

© 2002/2003 Jeremy Aiyadurai . All Rights Reserved