2013-08-23 31 views
0

我知道這是一個老話題,我曾試圖 看看互聯網的解決方案。代碼是有點直截了當,但不能讓它 工作。德爾福6如何使用CDO_TLB發送電子郵件

我已經有了代碼,但德爾福6給了我一個消息

「SendUsing」配置值無效

我的目標是發送一個文件附加到自己的Gmail帳戶。

procedure TForm1.Button1Click(Sender: TObject); 
var 
    M: IMessage; 
    s: string; 
begin 
    //uses CDO_TLB; 

    M := CoMessage.Create; 
    M.From := '[email protected]'; 
    M.To_ := '[email protected]'; 
    M.Subject := 'This is subject' + datetimetostr(now); 
    M.TextBody := 'This is text body' + datetimetostr(now); 

    s := 'http://schemas.microsoft.com/cdo/configuration/'; 
    with M.Configuration.Fields do begin 
    Item[s + 'sendusing'].Value := cdoSendUsingPort; 
    Item[s + 'smtpserver'].Value := 'smtp.gmail.com'; 
    Item[s + 'smtpauthenticate'].Value := cdoBasic ; 
    Item[s + 'sendusername'].Value := 'myname'; 
    Item[s + 'sendpassword'].Value := 'mypassword'; 
    Item[s + 'smtpserverport'].Value := 465; 
    Item[s + 'smtpusessl'].Value := False; 
    Item[s + 'smtpconnectiontimeout'].Value := 5; // default is 30 seconds 
    Update; 
    end; 

    try 
    M.Send; 
    // success 
    except 
    // fail 
    on E: Exception do 
     ShowMessage(E.Message); 
    end; 
end; 
+0

你試過設置'smtpusessl'爲true。 TCP端口465通常用於帶SSL的SMTP。 –

回答

1
procedure TForm1.Button1Click(Sender: TObject); 
var 
    M: IMessage; 
    s: string; 
begin 
    //uses CDO_TLB; 
    M := CoMessage.Create; 
    M.From := '[email protected]'; 
    M.To_ := '[email protected]'; 
    M.Subject := 'This is subject' + datetimetostr(now); 
    M.TextBody := 'This is text body' + datetimetostr(now); 
    s := 'http://schemas.microsoft.com/cdo/configuration/'; 
    with M.Configuration.Fields do begin 
    Item[s + 'sendusing'].Value := cdoSendUsingPort; 
    Item[s + 'smtpserver'].Value := 'smtp.gmail.com'; 
    Item[s + 'smtpauthenticate'].Value := cdoBasic ; 
    Item[s + 'sendusername'].Value := '[email protected]'; 
    Item[s + 'sendpassword'].Value := 'mypassword'; 
    Item[s + 'smtpserverport'].Value := 465; 
    Item[s + 'smtpusessl'].Value := True; 
    Item[s + 'smtpssl'].Value:='yes'; 
    Item[s + 'smtpconnectiontimeout'].Value := 5; // default is 30 seconds 
    Update; 
    end; 
    try 
    M.Send; 
    // success 
     ShowMessage('Sukses mengirim email!'); 
    except 
    // fail 
    on E: Exception do 
     ShowMessage(E.Message); 
    end;