关于indy9.0的问题,高分求助,谢谢!

shonsy 2004-02-24 03:16:20
//---------------------------------------------------------------------------

//发送邮件
//注:发送的SMTP属性通过SMTP_Setup函数设置了
//参数:in:cTo,收件人
// cCc 抄送
// cBcc 暗抄
// cSubject 主题
// cBody 内容
// cAttachList 发送的附件(以\n分割)
// OUT: Msg 返回错误信息
//返回值 0: 成功发送
// -1:失败,参见Msg信息
// -2: 没有先设置SMTP发送属性

int __fastcall TfrmEmailCfg::SendMail(const char * cTo, const char * cCc, const char * cBcc, const char * cSubject, const char * cBody, const char* cAttachList, char * cMsg)
{
int iRet=0;
if(!SetupOk)
return -2;

IdMsgSend->Clear(); //清除,否则包含有上一条的信息

//IdMsgSend->ContentType = ContentType;
IdMsgSend->From->Text = m_LocalMail;
if (ReturnReciept)
{//{We set the recipient to the From E-Mail address }
IdMsgSend->ReceiptRecipient->Text = IdMsgSend->From->Text;
}
else
{// {indicate that there is no receipt recipiant}
IdMsgSend->ReceiptRecipient->Text = "";
}

IdMsgSend->Recipients->EMailAddresses = cTo; //{ To: header }
IdMsgSend->Subject = cSubject; //{ Subject: header }
IdMsgSend->CCList->EMailAddresses = cCc;// {CC}
IdMsgSend->BccList->EMailAddresses = cBcc; //{BCC}

IdMsgSend->Priority = TIdMessagePriority(1); // { Message Priority }
IdMsgSend->Body->Text = String(cBody);

if(strlen(cAttachList))
{
TStringList * sl= new TStringList;
sl->Text=String(cAttachList);
for(int i=0;i<sl->Count;i++)
{
IdMsgSend->MessageParts->Add();
new TIdAttachment(IdMsgSend->MessageParts,sl->Strings[i]);
}
delete sl;
}
if(!SMTP->Connected())
{
try
{
SMTP->Connect();
}
catch(Exception &e)
{
strcpy(cMsg,"连接SMTP服务器失败!错误信息:");
strcat(cMsg,e.Message.c_str());
iRet = -1;
return iRet;
}
}
if(SMTP->Connected())
{
try
{
SMTP->Send(IdMsgSend);
}
catch(Exception &e)
{
strcpy(cMsg,e.Message.c_str());
iRet = -1;
}
}
else
{
strcpy(cMsg,"连接SMTP服务器失败!");
iRet = -1;
}
return iRet;
}

//-----------------------------------------------------------------------------
//设置发送的SMTP属性
//参数:in:cHost,SMTP服务器地址
// iPort, SMTP端口
// cLocalMail 发件人的邮箱
// iAuth 是否认证 0,不认证,1认证
// cUsername 认证用户名
// cPassword 认证密码
//
// OUT: 无
//返回值 0: 成功设置
// -1:失败,缺少属性
int __fastcall TfrmEmailCfg::SMTP_Setup(const char * cHost, const int iPort, const char *cLocalMail,
const int iAuth, const char * cUsername, const char *cPassword)
{
int iRet=0;
if(SMTP->Connected())
SMTP->Disconnect();
SMTP->Host = String(cHost);
SMTP->Port = iPort;
this->m_LocalMail = String(cLocalMail);

switch (iAuth)
{
// {authentication settings}
case 0:
SMTP->AuthenticationType = atNone;
break;
case 1:
SMTP->AuthenticationType = atLogin; //{Simple Login}
break;
}

SMTP->Username = cUsername;
SMTP->Password = cPassword;

SetupOk = true;
return iRet;
}


使用indy9.0中的例子进行编译时,总是提示:
[C++ Error] EmailCfg.cpp(138): E2316 'Username' is not a member of 'TIdSMTP'

试了很多遍也不好用,我第一遍运行成功,以后就总出这错误,郁闷中,都搞了一整天了,重写了N遍还是这样,求助,请高手指点,谢谢!
...全文
98 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
stiwin 2004-03-19
  • 打赏
  • 举报
回复
try{
if(!smtp->Connected()){
smtp->Connect(5000);
smtp->Authenticate();
}
}catch(...){
smtp->Disconnect();
return false;
}

TIdMessage *MailMsg =new TIdMessage(smtp);

try{
MailMsg->Subject="aaa"
MailMsg->Recipients->EMailAddresses ="aaaaa@163.com";
MailMsg->ReplyTo->EMailAddresses ="aaaaa@163.com";
MailMsg->From->Text ="aaaaa@163.com";
MailMsg->Sender->Text ="aaaaa@163.com";
MailMsg->CharSet="BIG5";
MailMsg->AddHeader("MIME-Version: 1.0");
MailMsg->Encoding=meMIME;
MailMsg->ContentType="text/plain";
MailMsg->Body->Text ="aaaaasdfksjdkf"
}catch(...){
smtp->Disconnect();
return false;
}

try{
smtp->Send(MailMsg);
}catch(...){}

MailMsg=NULL;
smtp->Disconnect();

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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