PureSMTP library
Overview
Send e-mails with Purebasic (PB 4.5x version).Functions
PureSMTP_SkipInitNetwork(SkipInit.l)Skip InitNetwork() call.PureSMTP_OpenPOP3ThenSMTPConnection(pop3server.s, POP3Port.l, POP3UserName.s, POP3UserPassword.s, SMTPServer.s, SMTPPort.l)
By default, the library will call InitNetwork().
Note that InitNetwork() must only be called once. Use this function if you call InitNetwork() in your program to avoid the library calling it for the second time.
PureSMTP_SkipInitNetwork() must be called before any other function of this library.
Open connection to POP3 server (authentication) and then to SMTP server.PureSMTP_OpenSMTPConnection(SMTPServer.s, SMTPPort.l)
Returns #PureSMTP_Ok if success (else is error code).
Note : if you call PureSMTP_OpenPOP3ThenSMTPConnection() without having closed the previous connection, PureSMTP will just keep using current connection.
Open connection to SMTP server.PureSMTP_SendMail(MailTo.s, MailFrom.s, Subject.s, MsgBody.s [, Attachments.s [, UserName.s [, Password.s [, HeaderAddon.s]]]])
Returns #PureSMTP_Ok if success (else is error code).
Note : if you call PureSMTP_OpenSMTPConnection() without having closed the previous connection, PureSMTP will just keep using current connection.
Send mail (and attached files).PureSMTP_CloseSMTPConnection()
Returns #PureSMTP_Ok if success (else is error code).
Sender :
Supports simple mail address ("name@domain.com") or real name + mail address ("Name <name@domain.com>")
Recipient(s) :
Supports simple mail address ("name@domain.com") or real name + mail address ("Name <name@domain.com>")
- 1 recipient : MailTo.s = "User1@Server1.fr"
- X recipients : MailTo.s = "User1@Server1.fr;User2@Server2.us;...;UserX@ServerX.ru"
To specify Carbon copy (CC:) or Blind Carbon Copy (BCC:), just add cc: or bcc: before the address :
- X recipients : MailTo.s = "User1@Server1.fr;cc:User2@Server2.us;bcc:UserX@ServerX.ru"
Attachements :
- file attachments :
- no file attached : Attachements.s = ""
- 1 file attached : Attachements.s = "Filename"
- X files attached : Attachements.s = "Filename1;Filename2;...;FilenameX"
- memory attachments : you may specify a memory bank instead of a filename.
- syntax : use "mem:{Filename}:{*InputBuffer}:{InputBufferLength}" instead of "{Path+Filename}"
- example :
If ReadFile(666, "c:\Purebasic450\Program\test.zip")
InMemAttachmentLen = Lof(666)
*InMemAttachment = AllocateMemory(InMemAttachmentLen)
If *InMemAttachment
ReadData(666, *InMemAttachment, InMemAttachmentLen)
Attachments.s = "mem:test.zip:" + Str(*InMemAttachment) +":" + Str(InMemAttachmentLen)
EndIf
CloseFile(666)
EndIf
- you may mix file and memory attachments :
- example : Attachements.s = "c:\files\:MyAttachment1.txt;mem:MyAttachment2.txt:5655524:2547;c:\files\:MyAttachment3.txt"
Authentication :
- SMTP AUTH : if the SMTP server requires authentication, use the optional parameters UserName and PassWord.
- POP3 AUTH : use the PureSMTP_OpenPOP3ThenSMTPConnection() function before PureSMTP_SendMail().
Optional header :
You can add a header text with the optional parameter HeaderAddon.
Example : HeaderAddon.s = "Date: 05 May 2005 12:00:00".
Close the SMTP connection.PureSMTP_GetLastServerMessage()
Get last server message.PureSMTP_SetTimeOut(TimeOut.l)
Usefull after a #PureSMTP_BadResponse error.
Set timeout for PureSMTP_SendMail() in seconds.PureSMTP_SetContentType(ContentType.s)
Default value = 15.
Set content type.PureSMTP_SetXMailer(XMailer.s)
Default ContentType value = "text/plain; charset=iso-8859-1".
Note : if ContentType = "!disabled!", Pure_SMTP does not process the headers, i.e. 'Content-Type:' and 'Content-Transfer-Encoding:' are not sent.
Set X-Mailer.PureSMTP_SetBoundary(Boundary.s)
Default is "PureSMTP".
Set Boundary for multipart/mixed message.PureSMTP_AddHeader(Header.s, String.s)
Default is "PureSMTP_".
Set additional header strings.PureSMTP_ClearHeader()
The headers are defined for the next PureSMTP_SendMail() calls. Don't define them each time before calling PureSMTP_SendMail() !
Clears the additional the header strings.PureSMTP_POP3Messages(pop3server.s, POP3Port.l, POP3UserName.s, POP3UserPassword.s)
Returns number of e-mails at POP3 server [>= 0 , else is error code].PureSMTP_SetAttachmentCallback(*ProcedureAddress)
Set a PureSMTP_SendMail() user callback.
When using PureSMTP_SendMail() with attachment files, it can take some time to finish the operation depending of the size of the attached files.
So the programmer might need to know and display the progress. This can be done using the callback.
The callback is like this :
Procedure MyCallback(AttachmentNumber.l, Progression.f)
; AttachmentNumber : attachment number [1 - X]
; Progression : attachment sending progression [0 - 100 %]
Debug "Attachement n°" + Str(AttachmentNumber) + " : " + StrF(Progression) + "%"
EndProcedure
And defined like this :
PureSMTP_SetAttachmentCallback(@MyCallback())
Callback return value
If the callback returns #True (<> #Null), the PureSMTP_SendMessage() function aborts and closes the connection to the SMTP server.
The message is not sent and PureSMTP_SendMessage() returns #PureSMTP_Abort error.