/////////////////////////////////////////////////////////////////////////////
// Function name : CMailObj::SubmitMail
// Description : Creates a new message in the message store
//
// Return type : BOOL - RETURNS TRUE if Successful, FALSE otherwise.
//
// Argument : LPTSTR lpszTo - Pointer to a string containing
// Recipient's Name.
//
// Argument : LPTSTR lpszSubject - Pointer to a string containing
// the Message Subject.
//
// Argument : LPTSTR lpszBody - Pointer to a string containing
// the Body of the Message.
//
// Argument : LPTSTR lpszAttach - Pointer to a string containing
// the path & file of the attachment.
//
BOOL CEMailHandler::SubmitMail(LPTSTR lpszTo, LPTSTR lpszSubject, LPTSTR lpszBody, LPTSTR lpszAttachPath)
{
BOOL bReturn = TRUE;
HANDLE phNewMail = NULL;
MailMsg Msg;
MailAtt MAtt;
// Check for an attachment
if (*lpszAttachPath)
{
// Clear the MailAtt Structure
memset(&MAtt, 0, sizeof(MailAtt));
// Setup the Mail Attachment Structure
MAtt.uiAttachmentNumber = 1;
MAtt.dwFlags = NULL;
//MAtt.ulCharacterPosition; // NOT SUPPORTED YET!
MAtt.ulSize = NULL; // Not needed since we are sending a local file
// MAtt.szOriginalName = TEXT("Pièce jointe");
MAtt.szOriginalName = lpszAttachPath;
MAtt.szLocalName = lpszAttachPath;
}
// Open the message store and obtain a handle to the mail context
bReturn = MailOpen ( &phNewMail, TRUE );
// Check for Success
if ( ( bReturn ) && ( NULL != phNewMail ) )
{
bReturn = FALSE;
// Clear the MailMsg
memset ( &Msg, 0, sizeof ( MailMsg ) );
// Specify which transport service we want to send the message.
Msg.szSvcNam = TEXT("Projet");
// Specify that we want the msg placed in the Outbox to be sent.
Msg.dwFlags = MAIL_FOLDER_OUTBOX | MAIL_STATUS_COMPOSED;
// Set the pointer to the Body of the message.
Msg.szBody = lpszBody;
// Set our Header up.
bReturn = MailSetField ( &Msg, TEXT( "To" ), lpszTo );
bReturn = MailSetField ( &Msg, TEXT( "Subject" ), lpszSubject );
// Set Date
SYSTEMTIME tTime;
FILETIME ftTime;
GetSystemTime(&tTime);
SystemTimeToFileTime(&tTime, &ftTime);
Msg.ftDate = ftTime;
// Place the message on the message store.
bReturn = MailPut ( phNewMail, &Msg );
if (( bReturn ) && ( NULL != &Msg ))
{
if(*lpszAttachPath)
{
#ifdef _DEBUG
char outstring[300];
wsprintf((unsigned short*)outstring, L"Attachment Path = \"%s\" \n", MAtt.szLocalName);
OutputDebugString((unsigned short *)outstring);
#endif
// Note that MailPutAttachment will attach the file to
// the mailmsg and also DELETE THE ORIGINAL FILE.
// You might want to copy the original file
// before attaching it. Also note that since it deletes
// the original, you will get an error when attempting
// to attach a file that exists on ROM.
bReturn = MailPutAttachment(phNewMail, &Msg, &MAtt);
}
}
}
// Release our new Mail Handle
if(phNewMail) MailClose(phNewMail);
return bReturn;
}
Partager