BSMTP DLL

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.

Using from Visual Basic

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

Sending emails with API from Visual C++ 6.0

Sending emails with API from Visual C++ 4.2/5.0

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);

Sending emails with API from Delphi

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;

How to use mail header

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"

How to confirm SMTP server

You can use telnet command to confirm the SMTP server. Use telnet command with 25 as port-number like below:

> telnet ServerName 25

Receiving emails with APIs

These functions enable you to receive emails on POP3 protocol.

  • Usage of BPOP3 and BMIME functions.
    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);
    
  • Warning:

    I've made sure to work these functions ONLY ON Visual C++.


    Important Note of BABAQ Free Soft

    Home


    Copyright 1997-1999 Tatsuo Baba,All rights reserved.