发送邮件的问题

HMODULE hMod=LoadLibrary("MAPI32.DLL");
if(hMod == NULL)
{
printf("LoadLibrary fail.\n");
return ;
}

ULONG (PASCAL *lpfnSendMail) (ULONG, ULONG, MapiMessage *, FLAGS, ULONG);
(FARPROC &)lpfnSendMail=GetProcAddress(hMod, "MAPISendMail");
if(lpfnSendMail == NULL)
{
printf("GetProcAddress fail.\n");
return ;
}

MapiFileDesc attachment=
{
0, // ulReserved, must be 0
0, // no flags; this is a data file
(ULONG) - 1, // position not specified
argv[0], // pathname, if original filename is NULL, this is the filename
NULL, // original filename
NULL
}; // MapiFileTagExt unused
MapiRecipDesc recip={ 0, MAPI_TO,"nowcan", "nowcan@163.com", 0, NULL };

MapiMessage message=
{
0, // reserved, must be 0
"测试", // subject
"我在csdn的名称是\n\nBIOS测试结果见附件。", // note text
NULL, // NULL = interpersonal message
NULL, // no date; MAPISendMail ignores it
NULL, // no conversation ID
0L, // no flags, MAPISendMail ignores it
NULL, // no originator, this is ignored too
1, // recipients
&recip, // recipient array
1, // one attachment
&attachment
}; // the attachment structure
int nError=lpfnSendMail(0, 0, &message, MAPI_LOGON_UI | MAPI_DIALOG, 0);

// after returning from the MAPISendMail call, the window must
// be re-enabled and focus returned to the frame to undo the workaround
// done before the MAPI call.

if(nError != SUCCESS_SUCCESS && nError != MAPI_USER_ABORT && nError != MAPI_E_LOGIN_FAILURE)
{
printf("SendMail fail.\n");
}

FreeLibrary(hMod);

这段代码可以用来发邮件,在控制台里完全没有问题,如果普通的就会有问题,弹出来的outlook窗体不能控制,不知道什么原因,请指教,这个代码是在nowcan的网站的
...全文
216 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Leighf 2005-03-08
  • 打赏
  • 举报
回复
up
同问!
datland 2004-10-05
  • 打赏
  • 举报
回复
最好用多线程.
发现一个可以下载(Delphi)代码的地方:
http://www.datcn.com/luntan/dispbbs.asp?boardID=26&ID=879
65867135 2004-10-05
  • 打赏
  • 举报
回复
一点都不懂啊 感觉自己苯死了
特招 2004-09-22
  • 打赏
  • 举报
回复
在头文件里加上

#include “idcoder3to4.hpp“

用Base64Encode()函数对用户名和密码编码


void __fastcall TForm1::Button1Click(TObject *Sender)
{
NMSMTP1->Host = "smtp.163.com"; //SMTP主机名
NMSMTP1->UserID = "dgyanyong"; //用户名
NMSMTP1->PostMessageA->FromAddress = "dgyanyong@163.com"; //发信人地址
NMSMTP1->PostMessageA->ToAddress->Clear(); //收信人地址清空
NMSMTP1->PostMessageA->ToAddress->Text = "dgyanyong@sina.com"; //收信人地址
NMSMTP1->PostMessageA->ToCarbonCopy->Text = "dgyanyong@chinaren.com"; //抄送地址
NMSMTP1->PostMessageA->ToBlindCarbonCopy->Text = "dgyanyong@163.com"; //暗送地址
NMSMTP1->PostMessageA->Subject = "test message"; //邮件标题
NMSMTP1->PostMessageA->Body->Add("this is a test message!"); //邮件内容
NMSMTP1->PostMessageA->Attachments->Text = "C:\\qq.doc"; //邮件附件
NMSMTP1->PostMessageA->LocalProgram = "SendMail";
NMSMTP1->Connect();
if (CheckBox1->Checked == true)
{
AnsiString userName = Base64Encode("dgyanyong"); //将用户名编码
AnsiString password = Base64Encode("dgyanyong"); //将密码编码
NMSMTP1->Transaction("auth login"); //开始验证
NMSMTP1->Transaction(userName);
NMSMTP1->Transaction(password);
}
NMSMTP1->SendMail();
Memo1->Lines->Add("发送邮件成功");
NMSMTP1->Disconnect();

}
  • 打赏
  • 举报
回复
#include <windows.h>
#include <mapi.h>
#include <stdio.h>
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{

}
//---------------------------------------------------------------------------


void SendEmail(char* str_name,char* str_email,char* str_subject,char* str_Text,char* pathname)
{
HMODULE hMod=LoadLibrary("MAPI32.DLL");
if(hMod == NULL)
{
//printf("LoadLibrary fail.\n");
return ;
}

ULONG (PASCAL *lpfnSendMail) (ULONG, ULONG, MapiMessage *, FLAGS, ULONG);
(FARPROC &)lpfnSendMail=GetProcAddress(hMod, "MAPISendMail");
if(lpfnSendMail == NULL)
{
//printf("GetProcAddress fail.\n");
return ;
}

MapiFileDesc attachment=
{
0, // ulReserved, must be 0
0, // no flags; this is a data file
(ULONG) - 1, // position not specified
pathname,//argv[0], // pathname, if original filename is NULL, this is the filename
NULL, // original filename
NULL
}; // MapiFileTagExt unused
MapiRecipDesc recip={ 0, MAPI_TO, str_name, str_email, 0, NULL };

MapiMessage message=
{
0, // reserved, must be 0
str_subject,//"测试", // subject
str_Text,//"我在csdn的名称是\n\nBIOS测试结果见附件。", // note text
NULL, // NULL = interpersonal message
NULL, // no date; MAPISendMail ignores it
NULL, // no conversation ID
0L, // no flags, MAPISendMail ignores it
NULL, // no originator, this is ignored too
1, // recipients
&recip, // recipient array
1, // one attachment
&attachment
}; // the attachment structure
int nError=lpfnSendMail(0, 0, &message, MAPI_LOGON_UI | MAPI_DIALOG, 0);

// after returning from the MAPISendMail call, the window must
// be re-enabled and focus returned to the frame to undo the workaround
// done before the MAPI call.

if(nError != SUCCESS_SUCCESS && nError != MAPI_USER_ABORT && nError != MAPI_E_LOGIN_FAILURE)
{
//printf("SendMail fail.\n");
}

FreeLibrary(hMod);

}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
SendEmail("asc",
"test@163.com",
"Test",
"附件测试",
"C:\\3.ico");
}

完整代码大家说说啊
2001ligy 2004-09-20
  • 打赏
  • 举报
回复
up
molan020 2004-09-20
  • 打赏
  • 举报
回复
up
  • 打赏
  • 举报
回复
对了还要头文件

#include <mapi.h>
//#include <stdio.h>
//#include <windows.h>

我不行用控件,而且用shellExecute的话无法发送附件
哪位高手帮帮忙!
3q
特招 2004-09-20
  • 打赏
  • 举报
回复
这段代码不太清楚
不过发邮件的程序,其实很简单的
用IdSMTP和NMSMTP都很容易,例子详见:
http://blog.csdn.net/dgyanyong
参考一下,可以自己做个dll控制邮件的发送
molan020 2004-09-20
  • 打赏
  • 举报
回复
up
huabihan 2004-09-20
  • 打赏
  • 举报
回复
怎么发送文件到邮箱啊????

13,824

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧