My thanks to the author, in that without the original code, learning how to query email servers would have been a lot harder to figure out.
Note that finding POP3 and SMTP addresses is not normally the same as the provided @ispname.com that you use to receive new email after your account is set up. But the information is either available through your existing email client software, or should be available from your email provider's technical support.
Code: Select all
; English forum: http://jconserv.net/purebasic/viewtopic.php?t=6668&highlight=
; Author: TerryHough
; Date: 23. June 2003
Structure AccountInfo
Server.s
EmailID.s
password.s
EndStructure
Dim accounts.accountinfo(20)
;enter all the email accounts you want checked here.
;Note that you could read the entries from a text
;file you set up for the purpose, even encrypt and
;decrypt the contents as necessary, or add code to
;request the individual account passwords at the
;start of the program. If the program becomes
;resident, you could requery the mail serviers as
;frequently as necessary until you shut the PC down.
;If set on an alarm start basis, you would want the
;passwords protected from being found and used by
;others.
accounts(1)\Server="mail.earthlink.net"
accounts(1)\EmailID="First.LastName"
accounts(1)\password="primary.password"
accounts(2)\Server="pop.trends.net"
accounts(2)\EmailID="screenname"
accounts(2)\password="okaydokee"
accounts(3)\Server="mail.earthlink.net"
accounts(3)\EmailID="Wife's.emailname"
accounts(3)\password="herpassword"
accounts(4)\Server="pop.sprynet.com"
accounts(4)\EmailID="Her.Othername"
accounts(4)\password="otherpassword"
For a.l=1 To 20
If accounts(a)\EmailID>""
number_of.l=a
EndIf
Next
crlf$ = Chr(13)+Chr(10)
*Buffer = AllocateMemory(0, 5000)
;-----------------------------------------------------------------------
; POP3 - Check number of messages
; Written by TerryHough - last updated 06/23/2003
;-----------------------------------------------------------------------
For idx.l=1 To number_of
If InitNetwork()=0
MessageRequester("Error", "Can't initialize the network !", #MB_ICONSTOP)
Goto pau
EndIf
ConnectionID=OpenNetworkConnection(accounts(idx)\server, 110)
If ConnectionID=0
MessageRequester("Error","Unable to connect to "+accounts(idx)\server,#MB_ICONERROR)
Goto pau
EndIf
; Most POP3 servers send an ID message back upon connection
; check If OK And respond with USER ID
RequestLength.l = ReceiveNetworkData(ConnectionID, *Buffer, 5000)
Result$=PeekS(*Buffer,RequestLength)
Debug(result$)
If Left(Result$,3)<>"+OK"
MessageRequester("error","Did not receive acknowledge from "+accounts(idx)\server,#mb_iconerror)
Goto pau
EndIf
; Send the USER ID now. Some POP3 servers don't prompt for it,
; but expect it To be sent here.
SendNetworkString(ConnectionID,"USER "+accounts(idx)\EmailID+crlf$)
; Should get back a password request if USER ID is valid
RequestLength.l = ReceiveNetworkData(ConnectionID, *Buffer, 5000)
result$=PeekS(*Buffer,RequestLength)
Debug(result$)
If Left(Result$,3)<>"+OK"
MessageRequester("Error",accounts(idx)\server+" did not accept "+accounts(idx)\EmailID,#MB_ICONERROR)
Goto pau
EndIf
; Send the PASSWORD now
SendNetworkString(ConnectionID, "PASS "+accounts(idx)\password+crlf$)
; Should get back a welcome message if password is accepted
RequestLength.l = ReceiveNetworkData(ConnectionID, *Buffer, 5000)
Result$=PeekS(*Buffer,RequestLength)
Debug(result$)
If Left(Result$,3)<>"+OK"
MessageRequester("Error",accounts(idx)\server+" did not accept the PASSWORD provided.",#MB_ICONERROR)
Goto pau
EndIf
; Send the LIST command to get number of available messages
SendNetworkString(ConnectionID, "LIST"+crlf$)
; Should get back a number of available messages
; Interpret based on the response receive, they vary and may
; include info about the message ids
RequestLength.l = ReceiveNetworkData(ConnectionID, *Buffer, 5000)
Result$ = PeekS(*Buffer,RequestLength)
Debug(result$)
Position.l = FindString(Reply$, "messages", 1)
If Position
MessageRequester("Info",Result$,#MB_ICONINFORMATION)
; You could use VAL(Left(Result$,position-2)) to
; determine how many messages, and place an Icon for
; each user of sound a different tone for each user
; mail is detected. But to do this properly, you
; would have to ensure that you only redisplay the
; icon or make the sound again if the amount of
; mail increases over the amount last reported.
EndIf
SendNetworkString(ConnectionID,"QUIT"+crlf$)
RequestLength.l = ReceiveNetworkData(ConnectionID, *Buffer, 5000)
Result$ = PeekS(*Buffer,RequestLength)
Debug(result$)
pau:
CloseNetworkConnection(ConnectionID)
Next
End
;Note: the following list of POSSIBLE mail servers
;is only To be used For debugging purposes. It
;first shows that there is no standard way to name
;a mail server. While you might see text with
;(POP3) or (SMTP) included, this usually is just
;used to indicate incoming mail protocol/server
;(POP3), ;and outgoing mail protocol/server (SMTP).
;Second, these servers will reject your efforts if
;you do not have a valid email account userid and
;password. After setting up a valid email account
;with any ISP or service provider, you will have
;to check the email client for the POP3 and SMTP
;settings to use with this program, or call their
;customer service for the needed information. Many
;free email services are available, but some only
;provide http:// services for their clients, meaning
;they will not work with this sample code. There
;are other email protocols as well, which may use
;a different port number besides 110, and which also
;involve different commands and capabilities.
;POP3 Servers: SMTP Servers
;mail.trends.net
;pop.protegy.net
;pop.amex.mail.net
;postoffice.worldnet.att.net
;popd.ix.netcom.com
;sprynet.com
;mail.earthlink.net smtpauth.earthlink.net
;fastmail.fm fastmail.fm
;pop.sbcglobal.net smtpauth.prodigy.net
;pop.sprintpcs.com
;mail.mac.com smtp.mac.com
;pop.ameritech.yahoo.com smtp.ameritech.yahoo.com
;pop.flash.yahoo.com smtp.flash.yahoo.com
;pop.nvbell.yahoo.com smtp.nvbell.yahoo.com
;pop.pacbell.yahoo.com smtp.pacbell.yahoo.com
;pop.prodigy.yahoo.com smtp.prodigy.yahoo.com
;pop.sbcglobal.yahoo.com smtp.sbcglobal.yahoo.com
;pop.snet.yahoo.com smtp.snet.yahoo.com
;pop.swbell.yahoo.com smtp.swbell.yahoo.com
;pop.wans.yahoo.com smtp.wans.yahoo.com