Command Line Send E-mail Component -- CmdEmail

How does CmdEmail work?
 

CmdEmail support command line interface, you call the program through command line. Supposed you have configed the program, you can send email to somebody just use a dos command. e.g.

sendmail -to:scott@tiger.com

The e-mail address scott@tiger.com (if exists) will receive a mail sent from you. Certainly the mail does not contains useful content you specified.

You need to specify the subject and mail body?
Okey, please create a message file and pass the file path to CmdEmail .

The messae file includes two parts, header and body.
Header : Specify the recipients, subject, location of attachment etc.
Body Text: The content of the email.

There is a empty line between header and body. The following is an example:

to:scott@tiger.com
cc:bill@microsoft.com
subject:hello scott
attachment:http://www.lv2000.com/sendmail.htm

First line of the body.
Second line.

Save the text above to C:\temp_name.txt . Run CmdEmail again, e.g.

sendmail -m:c:\temp_name.txt

CmdEmail will read information from the message file, then send a mail to sott@tiger.com, copy to bill@microsoft.com .

Download CmdEmail

CmdEmail User's Guide

Thank you for using our product CmdEmail.
CmdEmail is command line e-mail component, it can be integrated into
your application developed by Oracle Form Builder, VC, VB, Perl etc.

System Requirement
  --Microsoft windows system
--TCP/IP protocol installed
Installation
  1) Download latest version from www.lv2000.com
2) Decompress installation pack to the folder where you want to install the application files. We suggest you to install CmdEmail to windows PATH so that it can be called from any current working directory.
3) Setup your default e-mail account settings.
Uninstall CmdEmail
  CmdEmail is 'green' software, it will never change the registry.
If you do not need CmdEmail any more, please just remove the folder that contains CmdEmail.
How to setup e-mail account settings.
  Run this command line:

sendmail -setup

The Settings dialog will appear.Please input the information given to you by your Internet Service Provider (ISP) or administrator.

Your Name: Friendly name of the addresser.
Your e-mail address: The addresser of the mail.
Outgoing SMTP server: Please refer to your ISP or network administrator.
Port of SMTP server: Default 25
Read receipt requested: For MS outlook only.
User Name: User name used to login the smtp server.
Password: Password used to identify the user.

Note: Unless your ISP have indicated that your service uses Secure Password Authentication, do not select the "my outgoing server requires authentication" check box.

Command Line Usage Guide
 
Integrate CmdEmail into your applications
  CmdEmail support command line interface, it can be integrated to your applications developed by Oracle Form Builder, VC, VB, Perl etc

If you are using VB/VC, you can use WinExec() or CreateProgress() function to run CmdEmail. If you are developing form, you can use HOST built-in to run CmdEmail.
(See example below)

How to send short message with one single command line.
 

Since CmdEmail version 2 , two new paramters is added to CmdEmail.

-subject
-body

You can specify the subject and body by the two parameter.

The following small program written in javascript show you how to create the command line:

Example : ( 1, single line 2 multi-line 3 html )

Please input the receipts:

Please input the subject:

Use html format
Body:

Command Line:

 

How to pass many parameters to CmdEmail.
 

CmdEmail receive parameters from command line argument.
If you need to pass many parameters, you should create a file,
write the parameters to it. The file is called message file.

The message file contains two parts: Header and Body Text, delimiter between header and body is one empty line.

Header is composed by multi-line. format of each line:

<parameter-name>:<value>

Option parameter name:

to: Specify the recipients
cc: Carbon copy
subject: The subject of the mail
delete_the_file: If yes , the message file will be deleted when the email is sent.
*** The following options work with CmdEmail Pro ONLY.
user:Specify the user name used to login SMTP server
pwd: Specify the password used to login SMTP server
bcc: Blind carbon copy
attachment: Specify the path of the attachment.
fromaddr: Specify the addresser of the email
fromname: Specify the name of addresser.l

The mail body can be multi-line text.

Sample Codes
 

Sample code of sending mail via oracle forms

This section explains how to send mail from oracle forms through CmdEmail. Sure, the form should be running on Windows box.

--How to create message file. Please use TEXT_IO to create the message file.
--How to call CmdEmail. Please use HOST procedure to run CmdEmail.

We have created an example demonstrate how to use HOST procedure to run CmdEmail. Please download the form from http://www.lv2000.com/examples/testmail.fmb

Sample code:

DECLARE
v_file_path varchar2(300);
v_sendmail_exe_path varchar2(300);
text_file text_io.file_type;
BEGIN
v_sendmail_exe_path:='D:\cmdemail\sendmail.exe' ;--TODO: Change the path
v_file_path := 'd:\emailmsg.txt' ;--TODO:

if :mailto is null then
message('Please enter the e-mail address of the recipients');
raise form_trigger_failure;
end if;

text_file:=text_io.fopen(v_file_path,'w');
-- write header
text_io.put_line(text_file,'to:'||:mailto);
text_io.put_line(text_file,'cc:'||:copyto);
text_io.put_line(text_file,'attachment:c:\temp_file1.txt');
text_io.put_line(text_file,'attachment:c:\temp_file2.doc');
text_io.put_line(text_file,'subject:'||:subject);
text_io.put_line(text_file,'delete_the_file:yes');--delete the message file when the mail is sent successfully.
text_io.put_line(text_file,''); -- delimiter between header and body
-- write body
text_io.put_line(text_file,:mailbody);
text_io.fclose(text_file);
host(v_sendmail_exe_path||' -m:'||v_file_path,NO_SCREEN);
END ;


Integrate CmdEmail into program written in VC (1):

SECURITY_ATTRIBUTES g_sa = {sizeof(SECURITY_ATTRIBUTES),NULL,TRUE};

CString strTempPath;
GetTempPath( MAX_PATH, strTempPath.GetBuffer(MAX_PATH) );
strTempPath.ReleaseBuffer();
CString strTempName;
GetTempFileName( strTempPath, "m", 0, strTempName.GetBuffer(MAX_PATH) );
strTempName.ReleaseBuffer();
HANDLE hFile = CreateFile( strTempName, GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, &g_sa,
CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL );
if ( hFile != INVALID_HANDLE_VALUE )
{
DWORD dwLen=0;
CString sContent=_T("subject:this mail is sent by CmdEmail\r\n");
sContent += _T("\r\n");
sContent += _T("Dear Sir,\r\n");
sContent += _T("Hello world!\r\n");
WriteFile(hFile,sContent.GetBuffer(sContent.GetLength()),
sContent.GetLength(),&dwLen,NULL);
FlushFileBuffers(hFile);
CloseHandle(hFile);

CString sCommand=_T("D:\\working\\sendmail20\\Release\\sendmail.exe");
sCommand += _T(" -to:tiger@scott.com");
sCommand += _T(" \"-m:")+strTempName+_T("\"");

CString strTempNameOutput;
GetTempFileName( strTempPath, "m", 0, strTempNameOutput.GetBuffer(MAX_PATH) );
strTempNameOutput.ReleaseBuffer();
HANDLE hFileOutput = CreateFile( strTempNameOutput, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, &g_sa,
CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY|FILE_FLAG_DELETE_ON_CLOSE, NULL );

if(hFileOutput!= INVALID_HANDLE_VALUE ){

PROCESS_INFORMATION pi;
STARTUPINFO si = {0};
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
si.wShowWindow = SW_HIDE;
si.hStdOutput = hFileOutput;
si.hStdError = hFileOutput;
BOOL bOk = CreateProcess( NULL, sCommand.GetBuffer(1),
NULL, NULL, TRUE,
0, NULL,
NULL, &si, &pi );
if ( bOk )
{
CloseHandle( pi.hThread );
if (WaitForSingleObject(pi.hProcess,INFINITE ) == WAIT_OBJECT_0 ){
// flush the temp file's buffers....
BOOL bSucceed = FlushFileBuffers( hFileOutput );
// go to start of file....
DWORD dwPos = SetFilePointer( hFileOutput, 0, NULL, FILE_BEGIN );
char Buf[MAX_PATH];
ReadFile(hFileOutput,Buf,MAX_PATH-1,&dwLen,NULL);
if(dwLen>0){
if(dwLen<MAX_PATH)
*(Buf+dwLen)='\0';
MessageBox(Buf);
}else //sent successfully
MessageBox("sent");
}else{
MessageBox("failed");
}
CloseHandle( pi.hProcess );

}
CloseHandle(hFileOutput);
}
DeleteFile(strTempName);
}

Integrate CmdEmail into program written in VC (2):

SECURITY_ATTRIBUTES g_sa = {sizeof(SECURITY_ATTRIBUTES),NULL,TRUE};

CString strTempPath;
GetTempPath( MAX_PATH, strTempPath.GetBuffer(MAX_PATH) );
strTempPath.ReleaseBuffer();
CString strTempName;
GetTempFileName( strTempPath, "m", 0, strTempName.GetBuffer(MAX_PATH) );
strTempName.ReleaseBuffer();
HANDLE hFile = CreateFile( strTempName, GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, &g_sa,
CREATE_ALWAYS, 0, NULL );
if ( hFile != INVALID_HANDLE_VALUE )
{
DWORD dwLen=0;
CString sContent=_T("subject:this mail is sent by CmdEmail\r\n\r\n");
sContent += _T("Dear Sir,\r\n");
sContent += _T("Hello world!\r\n");
WriteFile(hFile,sContent.GetBuffer(sContent.GetLength()),sContent.GetLength() ,&dwLen,NULL);
FlushFileBuffers(hFile);
CloseHandle(hFile);

CString sCommand=_T("D:\\working\\sendmail20\\Release\\sendmail.exe");
sCommand += _T(" -to:tiger@scott.com");
sCommand += _T(" \"-m:")+strTempName+_T("\"");

if(WinExec(sCommand, SW_HIDE)>31)
MessageBox("sent");
}

 

 

Copyright© 2003-2004 Lion Soft Inc, All Rights Reserved.