線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1911
推到 Plurk!
推到 Facebook!

BCB6中Indy9發送郵件

 
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-02-25 20:12:07 IP:61.218.xxx.xxx 未訂閱
BCB6中Indy9發送郵件   作者: ChinaBCB
有兩個控件:TIdMessage:IdMsgSend, TIdSMTP:SMTP
/發送郵件
//註:發送的SMTP屬性通過SMTP_Setup函數設置了
//參數:in:cTo,收件人
//          cCc  抄送
//          cBcc 暗抄
//          cSubject 主題
//          cBody  內容
//          cAttachList 發送的附件(以\n分割)
//      OUT: Msg 返回錯誤信息
//返回值 0:  成功發送
//       -1:失敗,參見Msg信息
//       -2: 沒有先設置SMTP發送屬性
int __fastcall TM::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 = 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(Priority); // { Message Priority }
    IdMsgSend->Body->Text = String(cBody);        if(strlen(cAttachList))
    {
        TStringList * sl= new TStringList;
        sl->Text=String(cAttachList);
        for(int i=0;iCount;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 TM::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->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;
}
聯盟----Visita網站http://www.vista.org.tw ---[ 發問前請先找找舊文章 ]--- 發表人 - axsoft 於 2003/02/25 20:14:03
系統時間:2024-03-28 23:46:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!