[英]Sending Email in delphi
我的问题是这样的:我尝试发送带有 delphi 7 的 email,但是当我尝试发送它时,出现错误。
也许只是关于 TIdSMTP 的一个问题,它无法与 smtps 服务器连接,但我没有找到另一个使用 delphi 7 发送邮件的组件。
我的代码是这个:
unit Unit1;
interface
uses
inifiles, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdMessage, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdMessageClient, IdSMTP, DB, DBTables, ExtCtrls,
ComCtrls, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Button1: TButton;
MailMessage: TIdMessage;
SMTPS: TIdSMTP;
AttachmentDialog: TOpenDialog;
Body: TMemo;
StatusMemo: TMemo;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
private
public
Host : string;
Port : string;
Username : string;
Password : string;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Host, Username, Password : string;
begin
Host := 'smtps.aruba.it'; //Aruba SMTPS Host
Username := 'xxxx@xxxxxxx.xxx';
Password := 'yyyyyyyy';
//setup SMTP
SMTPS.Host := Host;
SMTPS.Port := 465;//SMTPS Port of Aruba
SMTPS.Username := Username;
SMTPS.Password := Password;
//setup mail message
MailMessage.From.Address := 'xxxxx@xxxxxxxx.xxx';
MailMessage.Subject := 'Subject';
MailMessage.Body.Text := 'Body Text';
//send mail
try
try
SMTPS.Connect(1000);
SMTPS.Send(MailMessage);
except on E:Exception do
showmessage(E.message);
end;
finally
if SMTPS.Connected then SMTPS.Disconnect;
end;
end;
end.
错误是这样的:
连接正常关闭
我遇到了完全相同的问题,所以我编写了一个为我找到正确设置的应用程序。 给你看的源码是https://github.com/Edijus/Email-Settings-Getter基本上,它循环遍历所有可能的TIdSMTPAuthenticationType, TIdSSLVersion, TIdUseTLS
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.