Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error C3861: '_T': identifier not found , unable to pass in main function parameters as function parameters

I am following this guide on using C++ to send emails. I followed the instructions and it works perfectly fine

This is the sample code on how to send emails using the program , I have changed the email address and password for security purposes

#include "stdafx.h"
#include <iostream>
#include "easendmailobj.tlh"
using namespace EASendMailObjLib;
using namespace std;

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("[email protected]");

    // Add recipient email address
    oSmtp->AddRecipientEx( _T("[email protected]"), 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 "[email protected]", then the user should be "[email protected]"
    oSmtp->UserName = _T("[email protected]");
    oSmtp->Password = _T("somepassword");

    _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();

    int x;
    cin>>x;

    return 0;
}

When i attempt to copy paste this code into my program and make it as a function which i can use , I get the following error

error C3861: '_T': identifier not found 

This is what my functions looks like

void DriverClass::send_email(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("randomemail1.com");

    // Add recipient email address
    oSmtp->AddRecipientEx( _T("[email protected]"), 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 "[email protected]", then the user should be "[email protected]"
    oSmtp->UserName = _T("[email protected]");
    oSmtp->Password = _T("randompassword");

    _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();

    int x;
    cin>>x;


}

I think it has something to do with the fact that i cant pass in int argc and _TCHAR*argc[] as arguements , How do make it into a function which i can use and how do i solve it ???

like image 448
Computernerd Avatar asked Feb 07 '14 09:02

Computernerd


1 Answers

Add:

#include <tchar.h>

as that is where the _T (and _TCHAR) macro is defined. See Generic-Text Mappings in Tchar.h.

like image 129
hmjd Avatar answered Oct 21 '22 17:10

hmjd