关于c++发送邮件解决方案
关于c++发送邮件
代码:
#include "stdafx.h"
int main(int argc, char* argv[])
{
typedef int (WINAPI ICEPUB_SENDMAILTEXT)(char *strUsername,char *strPassword,char *strSmtpServer,char *sendMail,char *toMailList,char *strSubject,char *strText);
ICEPUB_SENDMAILTEXT *icePub_sendMailText = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_sendMailText = (ICEPUB_SENDMAILTEXT *)GetProcAddress(hDLLDrv, "icePub_sendMailText");
}
if(icePub_sendMailText)
icePub_sendMailText("ahuinuli","112233","smtp.tom.com","ahuinuli@tom.com","mike@sina.com","标题:还好么?","文本:扉心祈梦,梦语问春天。");
if(hDLLDrv)
FreeLibrary(hDLLDrv);
}
这是我从网上找到的代码。还有一个动态库“icePubDll.dll”,"icePubDll.lib"等几个头文件
很久没有用vc了忘记怎么使用动态库了
调试后报错如下
--------------------Configuration: send - Win32 Debug--------------------
Compiling...
send.cpp
D:\vc\VC6\MyProjects\send\send\send.cpp(9) : error C2146: syntax error : missing ')' before identifier 'ICEPUB_SENDMAILTEXT'
D:\vc\VC6\MyProjects\send\send\send.cpp(9) : error C2146: syntax error : missing ';' before identifier 'ICEPUB_SENDMAILTEXT'
D:\vc\VC6\MyProjects\send\send\send.cpp(9) : error C2059: syntax error : ')'
D:\vc\VC6\MyProjects\send\send\send.cpp(9) : error C2065: 'ICEPUB_SENDMAILTEXT' : undeclared identifier
D:\vc\VC6\MyProjects\send\send\send.cpp(9) : error C2144: syntax error : missing ')' before type 'char'
D:\vc\VC6\MyProjects\send\send\send.cpp(9) : error C2059: syntax error : ')'
D:\vc\VC6\MyProjects\send\send\send.cpp(10) : error C2065: 'icePub_sendMailText' : undeclared identifier
D:\vc\VC6\MyProjects\send\send\send.cpp(10) : error C2106: '=' : left operand must be l-value
D:\vc\VC6\MyProjects\send\send\send.cpp(11) : error C2065: 'HINSTANCE' : undeclared identifier
D:\vc\VC6\MyProjects\send\send\send.cpp(11) : error C2146: syntax error : missing ';' before identifier 'hDLLDrv'
D:\vc\VC6\MyProjects\send\send\send.cpp(11) : error C2065: 'hDLLDrv' : undeclared identifier
D:\vc\VC6\MyProjects\send\send\send.cpp(11) : error C2065: 'LoadLibrary' : undeclared identifier
D:\vc\VC6\MyProjects\send\send\send.cpp(14) : error C2059: syntax error : ')'
D:\vc\VC6\MyProjects\send\send\send.cpp(19) : error C2065: 'FreeLibrary' : undeclared identifier
D:\vc\VC6\MyProjects\send\send\send.cpp(21) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.
send.exe - 1 error(s), 0 warning(s)
------解决方案--------------------
代码:
#include "stdafx.h"
int main(int argc, char* argv[])
{
typedef int (WINAPI ICEPUB_SENDMAILTEXT)(char *strUsername,char *strPassword,char *strSmtpServer,char *sendMail,char *toMailList,char *strSubject,char *strText);
ICEPUB_SENDMAILTEXT *icePub_sendMailText = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_sendMailText = (ICEPUB_SENDMAILTEXT *)GetProcAddress(hDLLDrv, "icePub_sendMailText");
}
if(icePub_sendMailText)
icePub_sendMailText("ahuinuli","112233","smtp.tom.com","ahuinuli@tom.com","mike@sina.com","标题:还好么?","文本:扉心祈梦,梦语问春天。");
if(hDLLDrv)
FreeLibrary(hDLLDrv);
}
这是我从网上找到的代码。还有一个动态库“icePubDll.dll”,"icePubDll.lib"等几个头文件
很久没有用vc了忘记怎么使用动态库了
调试后报错如下
--------------------Configuration: send - Win32 Debug--------------------
Compiling...
send.cpp
D:\vc\VC6\MyProjects\send\send\send.cpp(9) : error C2146: syntax error : missing ')' before identifier 'ICEPUB_SENDMAILTEXT'
D:\vc\VC6\MyProjects\send\send\send.cpp(9) : error C2146: syntax error : missing ';' before identifier 'ICEPUB_SENDMAILTEXT'
D:\vc\VC6\MyProjects\send\send\send.cpp(9) : error C2059: syntax error : ')'
D:\vc\VC6\MyProjects\send\send\send.cpp(9) : error C2065: 'ICEPUB_SENDMAILTEXT' : undeclared identifier
D:\vc\VC6\MyProjects\send\send\send.cpp(9) : error C2144: syntax error : missing ')' before type 'char'
D:\vc\VC6\MyProjects\send\send\send.cpp(9) : error C2059: syntax error : ')'
D:\vc\VC6\MyProjects\send\send\send.cpp(10) : error C2065: 'icePub_sendMailText' : undeclared identifier
D:\vc\VC6\MyProjects\send\send\send.cpp(10) : error C2106: '=' : left operand must be l-value
D:\vc\VC6\MyProjects\send\send\send.cpp(11) : error C2065: 'HINSTANCE' : undeclared identifier
D:\vc\VC6\MyProjects\send\send\send.cpp(11) : error C2146: syntax error : missing ';' before identifier 'hDLLDrv'
D:\vc\VC6\MyProjects\send\send\send.cpp(11) : error C2065: 'hDLLDrv' : undeclared identifier
D:\vc\VC6\MyProjects\send\send\send.cpp(11) : error C2065: 'LoadLibrary' : undeclared identifier
D:\vc\VC6\MyProjects\send\send\send.cpp(14) : error C2059: syntax error : ')'
D:\vc\VC6\MyProjects\send\send\send.cpp(19) : error C2065: 'FreeLibrary' : undeclared identifier
D:\vc\VC6\MyProjects\send\send\send.cpp(21) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.
send.exe - 1 error(s), 0 warning(s)
------解决方案--------------------
- C/C++ code
#include "windows.h" // jernymy int main(int argc, char* argv[]) { typedef int (WINAPI ICEPUB_SENDMAILTEXT)(char *strUsername,char *strPassword,char *strSmtpServer,char *sendMail,char *toMailList,char *strSubject,char *strText); ICEPUB_SENDMAILTEXT *icePub_sendMailText = 0; HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll"); if(hDLLDrv) { icePub_sendMailText = (ICEPUB_SENDMAILTEXT *)GetProcAddress(hDLLDrv, "icePub_sendMailText"); } if(icePub_sendMailText) icePub_sendMailText("ahuinuli","112233","smtp.tom.com","ahuinuli@tom.com","mike@sina.com","标题:还好么?","文本:扉心祈梦,梦语问春天。"); if(hDLLDrv) FreeLibrary(hDLLDrv); return 0; }