Delphi发送邮件的源码

发布网友 发布时间:2022-04-24 14:56

我来回答

1个回答

热心网友 时间:2022-05-03 08:13

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdMessage, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Memo1: TMemo;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
IdSMTP1: TIdSMTP;
IdMessage1: TIdMessage;
procere Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procere TForm1.Button1Click(Sender: TObject);
begin
with idmessage1 do
begin
body.Clear;
subject:=edit2.text;
From.Text:=edit4.text;
recipients.emailaddresses:=edit3.text;
body.assign(memo1.Lines);
ReceiptRecipient.Text := '';
//if edit7.Text='' then
//tidattachment.Create(idmessage1.MessageParts,edit7.Text);
end;
idsmtp1.authenticationtype:=atnone;
idsmtp1.UserId:=edit5.Text;
idsmtp1.Password:=edit6.Text;
idsmtp1.Host:='smtp.sohu.com';
idsmtp1.Port:=25;
{try
idsmtp1.Connect();
except
application.MessageBox('邮件发送失败!','提示',MB_OK+MB_ICONINFORMATION);
exit;
end;}
try
idsmtp1.Connect;
IdSMTP1.Send(IdMessage1);
application.MessageBox('邮件发送成功!','提示',MB_OK+MB_ICONINFORMATION);
finally
idsmtp1.Disconnect;
end;

end.

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com