EDN Admin
Well-known member
Hi,
I m trying to send a mail via c++ code. I downloaded EASendMail component installer in ma system.
Then using this i wrote a code in vc++. I m sending a mail using a gmail id.I m able to send the mail correctly.
The issue i m facing is that the code hangs for the time it takes to send the mail.when i get a notification tat the mail is sent , den the cursor becomes active.I send the receiver address to the function i m calling.
using namespace EASendMailObjLib;
using namespace std;
int SendMail(LPTSTR RecieverID)
{
::CoInitialize( NULL );
IMailPtr oSmtp = NULL;
oSmtp.CreateInstance( "EASendMailObj.Mail");
oSmtp->LicenseCode = L"TryIt";
// Set your gmail email address
oSmtp->FromAddr = L"mygmailid@gmail.com";
// Add recipient email address
oSmtp->AddRecipientEx( RecieverID, 0 );
// Set email subject
oSmtp->Subject = L"simple email from Visual C++ with gmail account";
oSmtp->BodyText = L"Hi ";
//adds attachment from local disk
if(oSmtp->AddAttachment( L"images/imagename.bmp") != 0)
{
printf("Failed to add attachment with error: %srn", (const TCHAR*)oSmtp->GetLastErrDescription());
}
// Gmail SMTP server address
oSmtp->ServerAddr = L"smtp.gmail.com";
// If you want to use direct SSL 465 port,
// Please add this line, otherwise TLS will be used.
// oSmtp->ServerPort = 465;
// detect SSL/TLS automatically
oSmtp->SSL_init();
// Gmail user authentication should use your
// Gmail email address as the user name.
oSmtp->UserName = L"mygmailid@gmail.com";
oSmtp->Password =L"passowrd123";
printf("Start to send email via gmail account ...rn" );
if( oSmtp->SendMail() == 0 )
{ printf("email was sent successfully!rn");
}
else
{ printf("failed to send email with the following error: %srn",(const TCHAR*)oSmtp->GetLastErrDescription());
}
if( oSmtp != NULL )
oSmtp.Release();
return 0;
}
I want the control to be active so that I can continue with other processes while the sending the mail happens on the background.
Can anyone pls help me in this !!!
Thankx a ton in advance.....
Regards,
Sandhya.
Sandhya
View the full article
I m trying to send a mail via c++ code. I downloaded EASendMail component installer in ma system.
Then using this i wrote a code in vc++. I m sending a mail using a gmail id.I m able to send the mail correctly.
The issue i m facing is that the code hangs for the time it takes to send the mail.when i get a notification tat the mail is sent , den the cursor becomes active.I send the receiver address to the function i m calling.
using namespace EASendMailObjLib;
using namespace std;
int SendMail(LPTSTR RecieverID)
{
::CoInitialize( NULL );
IMailPtr oSmtp = NULL;
oSmtp.CreateInstance( "EASendMailObj.Mail");
oSmtp->LicenseCode = L"TryIt";
// Set your gmail email address
oSmtp->FromAddr = L"mygmailid@gmail.com";
// Add recipient email address
oSmtp->AddRecipientEx( RecieverID, 0 );
// Set email subject
oSmtp->Subject = L"simple email from Visual C++ with gmail account";
oSmtp->BodyText = L"Hi ";
//adds attachment from local disk
if(oSmtp->AddAttachment( L"images/imagename.bmp") != 0)
{
printf("Failed to add attachment with error: %srn", (const TCHAR*)oSmtp->GetLastErrDescription());
}
// Gmail SMTP server address
oSmtp->ServerAddr = L"smtp.gmail.com";
// If you want to use direct SSL 465 port,
// Please add this line, otherwise TLS will be used.
// oSmtp->ServerPort = 465;
// detect SSL/TLS automatically
oSmtp->SSL_init();
// Gmail user authentication should use your
// Gmail email address as the user name.
oSmtp->UserName = L"mygmailid@gmail.com";
oSmtp->Password =L"passowrd123";
printf("Start to send email via gmail account ...rn" );
if( oSmtp->SendMail() == 0 )
{ printf("email was sent successfully!rn");
}
else
{ printf("failed to send email with the following error: %srn",(const TCHAR*)oSmtp->GetLastErrDescription());
}
if( oSmtp != NULL )
oSmtp.Release();
return 0;
}
I want the control to be active so that I can continue with other processes while the sending the mail happens on the background.
Can anyone pls help me in this !!!
Thankx a ton in advance.....
Regards,
Sandhya.
Sandhya
View the full article