Is there anything similar to VB mapisession in C++? I would like to email out a text file on the OS within in a C++ program; Or if you know how to invoke print to print the text file on OS within the C++ program.
// sEmailAddress and sFriendlyName are OUTPUT parameters.
// If the function fails, it will return FALSE, and the OUTPUT
// parameters will not be touched.
BOOL CMailMessage::GetRecipient(CString & sEmailAddress, CString & sFriendlyName, int nIndex)
{
CRecipient to;
if( nIndex < 0 || nIndex > m_Recipients.GetUpperBound() )
return FALSE;
to = m_Recipients[ nIndex ];
sEmailAddress = to.m_sEmailAddress;
sFriendlyName = to.m_sFriendlyName;
return TRUE;
}
int CMailMessage::GetNumRecipients()
{
return m_Recipients.GetSize();
}
// Add Recipients
//
length = strlen( szRecipients );
buf = new TCHAR[ length + 1 ]; // Allocate a work area (don't touch parameter itself)
strcpy( buf, szRecipients );
for( pos = 0, start = 0; pos <= length; pos++ )
{
if( buf[ pos ] == ';' ||
buf[ pos ] == 0 )
{
// First, pick apart the sub-strings (separated by ';')
// Store it in sTemp.
//
buf[ pos ] = 0; // Redundant when at the end of string, but who cares.
sTemp = &buf[ start ];
// Now divide the substring into friendly names and e-mail addresses.
//
nMark = sTemp.Find( '<' );
if( nMark >= 0 )
{
sFriendly = sTemp.Left( nMark );
nMark2 = sTemp.Find( '>' );
if( nMark2 < nMark )
{
delete[] buf;
return FALSE;
}
// End of mark at closing bracket or end of string
nMark2 > -1 ? nMark2 = nMark2 : nMark2 = sTemp.GetLength() - 1;
sEmail = sTemp.Mid( nMark + 1, nMark2 - (nMark + 1) );
}
else
{
sEmail = sTemp;
sFriendly = "";
}
AddRecipient( sEmail, sFriendly );
start = pos + 1;
}
}
delete[] buf;
return TRUE;
}
// -----------------SMTP.h-----------------
// SMTP.h: interface for the CSMTP class.
// use the SMTP Protocol
// 1999-12-01 -obislavu-
// Note: Please keep this note!!!!
//////////////////////////////////////////////////////////////////////
//
// Helper Code
//
struct response_code
{
UINT nResponse; // Response we're looking for
TCHAR* sMessage; // Error message if we don't get it
};
enum eResponse
{
GENERIC_SUCCESS = 0,
CONNECT_SUCCESS,
DATA_SUCCESS,
QUIT_SUCCESS,
// Include any others here
LAST_RESPONSE // Do not add entries past this one
};
TCHAR response_buf[ RESPONSE_BUFFER_SIZE ];
static response_code response_table[];
};
// Note: the order of the entries is important.
// They must be synchronized with eResponse entries.
CSMTP::response_code CSMTP::response_table[] =
{
{ 250, "SMTP server error" }, // GENERIC_SUCCESS
{ 220, "SMTP server not available" }, // CONNECT_SUCCESS
{ 354, "SMTP server not ready for data" }, // DATA_SUCCESS
{ 221, "SMTP server didn't terminate session" } // QUIT_SUCCESS
};
BOOL CSMTP:isconnect()
{
BOOL ret;
if( !m_bConnected )
return TRUE;
// Disconnect gracefully from the server and close the socket
CString sQuit = _T( "QUIT\r\n" );
m_wsSMTPServer.Send( (LPCTSTR)sQuit, sQuit.GetLength() );
// No need to check return value here.
// If it fails, the message is available with GetLastError
ret = get_response( QUIT_SUCCESS );
m_wsSMTPServer.Close();
// Get the recipients into a single string
sTo = "";
CString sEmail = "";
CString sFriendly = "";
for( int i = 0; i < msg->GetNumRecipients(); i++ )
{
msg->GetRecipient( sEmail, sFriendly, i );
sTo += ( i > 0 ? "," : "" );
sTo += sFriendly;
sTo += "<";
sTo += sEmail;
sTo += ">";
}
msg->m_tDateTime = msg->m_tDateTime.GetCurrentTime();
// Format: Mon, 01 Jun 98 01:10:30 GMT
sDate = msg->m_tDateTime.Format( "%a, %d %b %y %H:%M:%S %Z" );
sHeader.Format( "Date: %s\r\n" "From: %s\r\n" "To: %s\r\n" "Subject: %s\r\n" "X-Mailer: <%s>\r\n\r\n",
// Include other extension lines if desired
(LPCTSTR)sDate,
(LPCTSTR)msg->m_sFrom,
(LPCTSTR)sTo,
(LPCTSTR)msg->m_sSubject,
(LPCTSTR)m_sMailerName );
return TRUE;
}
CString CSMTP:repare_body(CMailMessage * msg)
{
ASSERT( msg != NULL );
CString sTemp;
CString sCooked = "";
LPTSTR szBad = "\r\n.\r\n";
LPTSTR szGood = "\r\n..\r\n";
int nPos;
int nStart = 0;
int nBadLength = strlen( szBad );
sTemp = msg->m_sBody;
if( sTemp.Left( 3 ) == ".\r\n" )
sTemp = "." + sTemp;
//
// This is a little inefficient because it beings a search
// at the beginning of the string each time. This was
// the only thing I could think of that handled ALL variations.
// In particular, the sequence "\r\n.\r\n.\r\n" is troublesome.
// (Even CStringEx's FindReplace wouldn't handle that situation
// with the global flag set.)
//
while( (nPos = sTemp.Find( szBad )) > -1 )
{
sCooked = sTemp.Mid( nStart, nPos );
sCooked += szGood;
sTemp = sCooked + sTemp.Right( sTemp.GetLength() - (nPos + nBadLength) );
}
return sTemp;
}
if( !smtp.Disconnect() )
{
LogError( smtp.GetLastError() );
return FALSE;
}
See the // commented lines for the StdAfx.h.
Let me know if it is not working!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.