Release Notes August 1, 1999
Written by Hippo2000
BSMTP DLL provides APIs for sendiing and receiving emails. Calling these APIs make you easy to send and receive mails from your programs.These APIs are available from Microsoft Visual C++ , Visual Basic and Inprise Delphi. You can send a mail with Only 1 API call. You can write header files as you like.
When you want to call from Visual Basic, you should define functions with Declare statements like below:
Private Declare Function SendMail Lib "bsmtp" _ (szServer As String, szTo As String, szFrom As String, _ szSubject As String, szBody As String, szFile As String) As String Private Declare Function SendMailEx Lib "bsmtp" _ (szLogfile As String, szServer As String, szTo As String, _ szFrom As String, szSubject As String, szBody As String, szFile As String) As String Private Declare Function RcvMail Lib "bsmtp" _ (szServer As String, szUser As String, szPass As String, _ szCommand As String, szDir As String) As Variant Private Declare Function ReadMail Lib "bsmtp" _ (szFilename As String, szPara As String, szDir As String) As Variant
// Bsmtp DLL extern "C" __declspec(dllimport) int BSendMail( LPCSTR szServer, // smtp server name LPCSTR szTo, // To (Maximum length is 8192 bytes) LPCSTR szFrom, // From LPCSTR szSubject, // Subject LPCSTR szBody, // Body LPCSTR szFile, // Attached Files (Specify in Full-Path. Separate multiple files by a TAB.) LPSTR msg); // error message
char msg[80]; ok = BSendMail(server, // Name of SMTP server. // If you want to specify a port number, append it separating by a Tab. to, // To email address (e.g., who@who.com\twho2...) from, // From email address subj, // Message subject body, // Message body files, // Attached Files msg); // error message if (!ok) { sprintf(buffer,"Sending Error (%s) %s %s %s %s", msg,server,to,from,subj); }
In Visual C++ 4.2/5.0, somtimes to link bsmpt.lib with a program occurs error. Because bsmpt.dll is built in VC++ 6.0, I think. In this case, you can not use bsmtp.lib. But LoadLibrary / GetProcAddress enables you to call API function.
// Define prototype of the function with typedef. typedef int (*pBSendMail)( LPCSTR szServer, LPCSTR szTo, LPCSTR szFrom, LPCSTR szSubject, LPCSTR szBody, LPCSTR szFile, LPSTR msg); // Load BSMTP library HINSTANCE hInst = ::LoadLibrary("bsmtp.dll"); if (hInst == NULL) return false; // Declare a pointer for the function. pBSendMail pBs; // Set address of BSendMail into this pointer pBs = (pBSendMail)::GetProcAddress(hInst,"BSendMail"); if (pBs == NULL) { FreeLibrary(hInst); return false; } // Call BSendMail with that pointer int ok = pBs(Server,To,From,Sub,Body,"",msg); // Finally unload library FreeLibrary(hInst);
This function is also available from
Delphi. Delphi does not use lib files.
(Sample codes in this section are provided from hirano@linex.
Thank you)
Function BSendMail( szServer, // SMTP server name szTo, // To szFrom, // From szSubject, // Subject szBody, // Body szFile:LPCSTR; // Attached Files split by a TAB msg:LPSTR):Integer; // error message Stdcall external 'Bsmtp.dll'; procedure TForm1.Button1Click(Sender: TObject); var wkstr : array[0..80]of Char; begin if (BSendMail( PChar(Edit1.Text), // SMTP server name PChar(Edit2.Text), // To PChar(Edit3.Text), // From PChar(Edit4.Text), // Subject PChar(''), // Body PChar(Edit5.Text), // Attached Files split by a TAB wkstr) <> 0 )Then begin Showmessage('Send a Mail'); end else begin Showmessage(wkstr); end; end;
You can specify cc/bcc/reply keywords in "szTo" (2nd Parameter) separating with a TAB. If you want to specify a header entry defined by yourself, specify as you want adding a ">" at its head.
Exaple: -Sends a email To id1, CC to id2, and has "12345" as Message-ID information: szTo = "id1\tcc\tid2\t>Message-ID: 12345" -Sends a email To id1 and id2, CC to id3: szTo = "id1\tid2\tcc\tid2" -Sends a email To id1 and id2, CC to id3 and id4: szTo = "id1\tid2\tcc\tid3\tid4" -Sends a email to id1, BCC to id2: szTo = "id1\tbcc\tid2" -Sends a email to id1, CC to id2 and BCC to id3: szTo = "id1\tcc\tid2\tbcc\tid3" -Sends a email to id1 and Reply-To id2: szTo = "id1\treply-to\tid2" -Sends a email CC to id2: szTo = "cc\tid2" -Sends a email BCC to id2: szTo = "bcc\tid2"
You can use telnet command to confirm the SMTP server. Use telnet command with 25 as port-number like below:
> telnet ServerName 25
These functions enable you to receive emails on POP3 protocol.
struct RetArray { int counter; char* array[256]; }; extern "C" __declspec(dllimport) void BFreeArray(RetArray* parray); extern "C" __declspec(dllimport) int BPOP3( LPCSTR szServer, // POP3 server name LPCSTR szName, // NAME LPCSTR szPass, // PASSWORD LPCSTR szCommand, // COMMAND LPCSTR szPath, // Directory RetArray* RetArray, // return ARRAY LIST LPSTR msg // message area (80 bytes) ); extern "C" __declspec(dllimport) int BMIME( LPCSTR szCommand, // command name LPCSTR szFileName, // Target Name LPCSTR szPath, // Target Name RetArray* RetArray, // return ARRAY LIST LPSTR msg // message area (80 bytes) );
BPOP3 fuction receives emails from mail-server and write them into files.
ParametersF szServer * Name of POP3-server. IP-address is also available. If you want to specify the port-number, append it heading with a TAB. szName * Account name of mail user. szPass * Password of szName. 2000/05/20 APOP supported To use APOP, one blank is applied to "a" or "A" ahead of the password. "a xxxx" : If the server does not support APOP, usual USER/PASS will be processed. "A xxxx" : APOP is compelled. USER/PASS will not be used. szCommand * Command for this function.(cases are ignored ) STAT .... Returns the number and total bytes of emails. LIST .... Returns contents of Subject, From and Date header of all emails. SAVE n .... Receives the n-th email. SAVD n .... Receives the n-th email and remove it from the mailbox on server. SAVEALL ... Receives all emails. SAVEALLD ... Receives all emails and remove them from the mailbox on server. szPath * Directory name. The recieved emails are saved into this direcotry. RetArray * Array of strings that contains the result of this function. If a error occurs, none of these are returned. Contents of this depends on szCommand like below: LIST - Contents of Subjcet, From and Date headers, separeted by TABs. SAVExxx- Filenames into which received emails are saved. STAT - Number and total bytes of emails in mailbox. msg * Message buffer (80 bytes)
Return: * >1 Normal end.
BMIME function gets informations from a RFC822-formatted file which are saved by BPOP3 function. ParametersF szCommand@* Command of this function.(Ignored are cased) GET ...... Gets Header, Body, Attached files. GETNOF ... Gets Heder, Body HEAD ...... Gets only Header. szFileName * Name of a RFC822-formatted file that is saved by BPOP3 function. szPath * Direcotry name into whilch attached files are saved. RetArray * Array of strings that contains the result of function. If error occurs, none of this are returned. Contents of this depends on szCommand like below: GET - Header, Body, Attached filename. GETNOF - Header, Body. HEAD - Header. msg * Message buffer(80 bytes) Return : >=1 Normal end.
BFreeArray function will set free the memory which was allocated by BPOP3 and BMIME funcion.
PametersF parray * Address of RetArray Structure.
char msgx[80]; RetArray ret1,ret2; int rc = BPOP3( "server1","user1","pass1", "save 1","c:\\mail",&ret1,msgx); if (rc <= 0) return false; rc = BMIME("get",ret1.array[0],"c:\\mail",&ret2,msgx); if (rc > 0) { FILE *fp = ::fopen("c:\\mail\\mail.txt","wb"); for (int i= 0;i < rc ;i++) { ::fwrite(ret2.array[i],1,strlen(ret2.array[i]),fp); ::fwrite("\015\012",1,2,fp); // put CRLF } ::fclose(fp); } DeleteFile(ret1.array[0]); BFreeArray(&ret1); BFreeArray(&ret2);
I've made sure to work these functions ONLY ON Visual C++.
Copyright 1997-1999 Tatsuo Baba,All
rights reserved.