0

我知道这是一个老话题,我试图在互联网上寻找解决方案。代码有点直截了当,但无法使其正常工作。

我已经有了代码,但 delphi 6 给了我一条消息

“SendUsing”配置值无效

我的目标是将文件附件发送到我自己的 gmail 帐户。

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

  M := CoMessage.Create;
  M.From := 'myname@gmail.com';
  M.To_ := 'myname@gmail.com';
  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;
4

1 回答 1

1
procedure TForm1.Button1Click(Sender: TObject);
var
  M: IMessage;
  s: string;
begin
  //uses CDO_TLB;
  M := CoMessage.Create;
  M.From := 'myname@gmail.com';
  M.To_ := 'myname@gmail.com';
  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@gmail.com';
    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;
于 2014-04-30T13:01:12.997 回答