Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
ivan  
#1 Posted : Saturday, April 2, 2011 3:58:44 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,148

Thanks: 9 times
Was thanked: 54 time(s) in 54 post(s)
VC++ Example

Gmail SMTP server address is "smtp.gmail.com". It requires SSL or TLS connection, and you should use your Gmail email address as the user name for ESMTP authentication. For example: your email is "gmailid@gmail.com", and then the user name should be "gmailid@gmail.com".

// The following example codes demonstrate sending email message using Gmail SMTP server
// To get full sample projects, please download and install EASendMail on your machine.
// To run it correctly, please change SMTP server, user, password, sender, recipient value to yours

Code:

#include "stdafx.h" 

#include "easendmailobj.tlh" 
using namespace EASendMailObjLib; 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
    ::CoInitialize( NULL ); 

    IMailPtr oSmtp = NULL; 
    oSmtp.CreateInstance( "EASendMailObj.Mail"); 
    oSmtp->LicenseCode = _T("TryIt"); 

    // Set your gmail email address
    oSmtp->FromAddr = _T("gmailid@gmail.com"); 

    // Add recipient email address
    oSmtp->AddRecipientEx( _T("support@emailarchitect.net"), 0 ); 

    // Set email subject
    oSmtp->Subject = _T("simple email from Visual C++ with gmail account"); 

    // Set email body
    oSmtp->BodyText = _T("this is a test email sent from Visual C++ project with Gmail"); 

    // Gmail SMTP server address
    oSmtp->ServerAddr = _T("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.
    // For example: your email is "gmailid@gmail.com", then the user should be "gmailid@gmail.com"
    oSmtp->UserName = _T("gmailid@gmail.com"); 
    oSmtp->Password = _T("yourpassword"); 

    _tprintf(_T("Start to send email via gmail account ...\r\n" )); 

    if( oSmtp->SendMail() == 0 ) 
    { 
        _tprintf( _T("email was sent successfully!\r\n")); 
    } 
    else 
    { 
        _tprintf( _T("failed to send email with the following error: %s\r\n"), 
            (const TCHAR*)oSmtp->GetLastErrDescription()); 
    } 

    if( oSmtp != NULL ) 
        oSmtp.Release(); 

    return 0; 
} 

Click here to read original topic - full version ...

If you have any comments or questions about above example codes, please add your comments here.

Edited by user Wednesday, January 21, 2015 6:41:44 PM(UTC)  | Reason: Not specified

kmtompkins  
#2 Posted : Sunday, January 4, 2015 4:41:38 PM(UTC)
kmtompkins

Rank: Newbie

Groups: Registered
Joined: 1/4/2015(UTC)
Posts: 2
United States
Location: New York

hi i am using the code that u made for Visual C++ - Send Email using Gmail Account i have changed a few thing because i was getting errors and i was able to get the code to run but at the line:
if (oSmtp->SendMail() == 0)

it crashes, the program just stops responding

Code:

// The following example codes demonstrate sending email message using Gmail SMTP server
// To get full sample projects, please download and install EASendMail on your machine.
// To run it correctly, please change SMTP server, user, password, sender, recipient value to yours

#define _AFXDLL
#include "stdafx.h" 

#include "easendmailobj.tlh" 
using namespace EASendMailObjLib;

int _tmain(int argc, char* argv[])
{
	::CoInitialize(NULL);

	IMailPtr oSmtp = NULL;
	oSmtp.CreateInstance("EASendMailObj.Mail");
	oSmtp->LicenseCode = ("TryIt");

	// Set your gmail email address
	oSmtp->FromAddr = ("gmailid@gmail.com");

	// Add recipient email address
	oSmtp->AddRecipientEx(("gmailid@gmail.com"), 0);

	// Set email subject
	oSmtp->Subject = ("simple email from Visual C++ with gmail account");

	// Set email body
	oSmtp->BodyText = ("this is a test email sent from Visual C++ project with Gmail");

	// Gmail SMTP server address
	oSmtp->ServerAddr = ("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.
	// For example: your email is "gmailid@gmail.com", then the user should be "gmailid@gmail.com"
	oSmtp->UserName = ("kmtompkinscode@gmail.com");
	oSmtp->Password = ("password here");

	printf("Start to send email via gmail account ...\r\n");

	if (oSmtp->SendMail() == 0)//program crashes here
	{
		printf("email was sent successfully!\r\n");
	}
	else
	{
		printf("failed to send email with the following error: %s\r\n"),
			(const TCHAR*)oSmtp->GetLastErrDescription();
	}

	if (oSmtp != NULL)
		oSmtp.Release();

	return 0;
}

Edited by moderator Sunday, January 4, 2015 4:47:29 PM(UTC)  | Reason: Not specified

ivan  
#3 Posted : Sunday, January 4, 2015 4:46:37 PM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,148

Thanks: 9 times
Was thanked: 54 time(s) in 54 post(s)
Please try to use "Try-catch" to catch the error information.
It is likely that your trial period is expired, you can re-download the installer from our site and re-install it to get extend trial period.

Code:

int _tmain(int argc, char* argv[])
{
    ::CoInitialize(NULL);

  try
  {
    IMailPtr oSmtp = NULL;
    oSmtp.CreateInstance("EASendMailObj.Mail");
    oSmtp->LicenseCode = ("TryIt");

    // Set your gmail email address
    oSmtp->FromAddr = ("gmailid@gmail.com");

    // Add recipient email address
    oSmtp->AddRecipientEx(("gmailid@gmail.com"), 0);

    // Set email subject
    oSmtp->Subject = ("simple email from Visual C++ with gmail account");

    // Set email body
    oSmtp->BodyText = ("this is a test email sent from Visual C++ project with Gmail");

    // Gmail SMTP server address
    oSmtp->ServerAddr = ("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.
    // For example: your email is "gmailid@gmail.com", then the user should be "gmailid@gmail.com"
    oSmtp->UserName = ("gmailid@gmail.com");
    oSmtp->Password = ("****");

    printf("Start to send email via gmail account ...\r\n");

    if (oSmtp->SendMail() == 0)//program crashes here
    {
        printf("email was sent successfully!\r\n");
    }
    else
    {
        printf("failed to send email with the following error: %s\r\n"),
            (const TCHAR*)oSmtp->GetLastErrDescription();
    }

    if (oSmtp != NULL)
        oSmtp.Release();
  
   }catch( _com_error &ep )
   {
        _tprintf( _T("Error: %s"), (const TCHAR*)ep.Description());
   }

   return 0;
}

Edited by user Monday, January 5, 2015 12:12:34 AM(UTC)  | Reason: Not specified

kmtompkins  
#4 Posted : Sunday, January 4, 2015 5:19:45 PM(UTC)
kmtompkins

Rank: Newbie

Groups: Registered
Joined: 1/4/2015(UTC)
Posts: 2
United States
Location: New York

ok u have a extra } with out it the program runs but it still crashes in the same spot

Code:

// The following example codes demonstrate sending email message using Gmail SMTP server
// To get full sample projects, please download and install EASendMail on your machine.
// To run it correctly, please change SMTP server, user, password, sender, recipient value to yours

#define _AFXDLL
#include "stdafx.h" 

#include "easendmailobj.tlh" 
using namespace EASendMailObjLib;

int _tmain(int argc, char* argv[])
{
	::CoInitialize(NULL);

	try
	{
		IMailPtr oSmtp = NULL;
		oSmtp.CreateInstance("EASendMailObj.Mail");
		oSmtp->LicenseCode = ("TryIt");

		// Set your gmail email address
		oSmtp->FromAddr = ("gmailid@gmail.com");

		// Add recipient email address
		oSmtp->AddRecipientEx(("gmailid@gmail.com"), 0);

		// Set email subject
		oSmtp->Subject = ("simple email from Visual C++ with gmail account");

		// Set email body
		oSmtp->BodyText = ("this is a test email sent from Visual C++ project with Gmail");

		// Gmail SMTP server address
		oSmtp->ServerAddr = ("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.
		// For example: your email is "gmailid@gmail.com", then the user should be "gmailid@gmail.com"
		oSmtp->UserName = ("gmailid@gmail.com");
		oSmtp->Password = ("****");

		printf("Start to send email via gmail account ...\r\n");

		if (oSmtp->SendMail() == 0)//program crashes here
		{
			printf("email was sent successfully!\r\n");
		}
		else
		{
			printf("failed to send email with the following error: %s\r\n"),
				(const TCHAR*)oSmtp->GetLastErrDescription();
		}

		if (oSmtp != NULL)
			oSmtp.Release();
	}

	catch (_com_error &ep)
	{
		_tprintf(_T("Error: %s"), (const TCHAR*)ep.Description());
	}

	return 0;
}
ivan  
#5 Posted : Monday, January 5, 2015 12:18:02 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,148

Thanks: 9 times
Was thanked: 54 time(s) in 54 post(s)
please have a try with the following codes:

this statement has a problem:

printf("failed to send email with the following error: %s\r\n"),
(const TCHAR*)oSmtp->GetLastErrDescription();

Did you re-install it?
It is likely that your trial period is expired, you can re-download the installer from our site and re-install it to get extend trial period.

Code:

int _tmain(int argc, char* argv[])
{
	::CoInitialize(NULL);

	try
	{
		IMailPtr oSmtp = NULL;
		oSmtp.CreateInstance("EASendMailObj.Mail");
		oSmtp->LicenseCode = ("TryIt");

		// Set your gmail email address
		oSmtp->FromAddr = ("gmailid@gmail.com");

		// Add recipient email address
		oSmtp->AddRecipientEx(("gmailid@gmail.com"), 0);

		// Set email subject
		oSmtp->Subject = ("simple email from Visual C++ with gmail account");

		// Set email body
		oSmtp->BodyText = ("this is a test email sent from Visual C++ project with Gmail");

		// Gmail SMTP server address
		oSmtp->ServerAddr = ("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.
		// For example: your email is "gmailid@gmail.com", then the user should be "gmailid@gmail.com"
		oSmtp->UserName = ("gmailid@gmail.com");
		oSmtp->Password = ("****");

		printf("Start to send email via gmail account ...\r\n");

		if (oSmtp->SendMail() == 0)//program crashes here
		{
			_tprintf(_T("email was sent successfully!\r\n"));
		}
		else
		{
			_tprintf(_T("failed to send email with the following error: %s\r\n"),
				(const TCHAR*)oSmtp->GetLastErrDescription());
		}

		if (oSmtp != NULL)
			oSmtp.Release();
	}

	catch( _com_error &ep )
	{
		_tprintf( _T("Error: %s"), (const TCHAR*)ep.Description());
	}

	return 0;
}

Edited by user Wednesday, January 21, 2015 6:42:32 PM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.110 seconds.

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.