我正在关注使用C ++发送电子邮件的guide。我按照说明操作,完美无缺
这是关于如何使用该程序发送电子邮件的示例代码,为了安全起见,我更改了电子邮件地址和密码
#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("randomemail1.lim@gmail.com");
// Add recipient email address
oSmtp->AddRecipientEx( _T("randomemail2s@hotmail.com"), 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("somerandomemail@gmail.com");
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;
}
当我尝试将此代码粘贴到我的程序中并将其作为我可以使用的函数时,我收到以下错误
error C3861: '_T': identifier not found
这就是我的功能
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("randomemail2@hotmail.com"), 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("randomemail1@gmail.com");
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;
}
我认为这与我无法传递int argc
和_TCHAR*argc[]
作为争论的事实有关,如何将其变成我可以使用的功能以及如何解决它? ??
答案 0 :(得分:27)