1

I am using an external library EASendMail to send email using gmail as an SMTP server .

The line causing the error

oSmtp->LicenseCode = _T("TryIt");

The link to install the external library .

#include "stdafx.h"
#include <iostream>
#include "easendmailobj.tlh"
#include <string>

using namespace EASendMailObjLib;
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{

    string Lrecipient_email = "foobar@hotmail.com";

    ::CoInitialize( NULL );

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

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

    // Add recipient email address
    oSmtp->AddRecipientEx( _T(recipient_email.c_str()), 0);

    // Set email subject
    oSmtp->Subject = _T("Payment of Desposit Required");

    // Set email body
    oSmtp->BodyText = _T("Dear Customer , Please pay your deposit now !!!");

    // 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("username");
    oSmtp->Password = _T("password");

    _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;
}

I have no idea why I am getting this following error :

Unhandled exception at 0x7558c41f in SendEmail.exe: Microsoft C++ exception: _com_error at memory location 0x0040f4ac..

The MS Studio debugger shows this as the source of error in the file : easendmailobj.tli

Error 1

 Interface* operator->() const 
    { 
        if (m_pInterface == NULL) 
        {
            _com_issue_error(E_POINTER);
        }

        return m_pInterface; 
    }

Error 2

inline void IMail::PutLicenseCode ( _bstr_t pVal ) {
    HRESULT _hr = put_LicenseCode(pVal);
    if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
}
M4N
  • 94,805
  • 45
  • 217
  • 260
Computernerd
  • 7,378
  • 18
  • 66
  • 95

3 Answers3

2

oSmtp->LicenseCode = _T("TryIt"); This error occurs when your trial version expires.

"TryIt" is evaluation license code and can be used only for demo purpose.After 1 month as license expires it raises an COM exception.

You can further check these links

https://www.emailarchitect.net/easendmail/sdk/html/LicenseCode.htm https://www.emailarchitect.net/easendmail/sdk/html/license.htm

Manvitha
  • 21
  • 3
0

The best thing to do is surround your entire code with

try{
....
}catch(_com_error& ex){
e=e;//a break point here
}

and step through your code with the debugger. As soon as it gets into the catch part it is the previously invoked method which caused it. usually with this COM stuff(I'm not to fond of it but somewhat familliar with it) it happend because an earlier method got wrong parameters so it returned a null pointer or something like that.

okaerin
  • 789
  • 5
  • 23
0
IMailPtr oSmtp = NULL;
oSmtp.CreateInstance( "EASendMailObj.Mail");

This may be the problem. First you are assigning a NULL to oSmtp, than you are trying to access it. Please verify, oSmtp is probably NULL.

bkausbk
  • 2,740
  • 1
  • 36
  • 52