首页 > 代码库 > 发送邮件(XE10.1+WIN764)

发送邮件(XE10.1+WIN764)

千万不要用QQ邮箱测试,我试了半天,没整明白。

 

uses
IdAttachmentFile,//引入

 

procedure TForm1.Button1Click(Sender: TObject);
begin
IdSMTP1.Host := ‘exchange.grandsoft.com.cn‘;
IdSMTP1.Port := 25;
IdSMTP1.username := ‘zhujq-a‘;//发送者用户名
IdSMTP1.password := ‘123456789‘;//密码用自己的
IdSMTP1.AuthType := satDefault;
IdSMTP1.Connect;//连接
idmessage1.CharSet := ‘gb2312‘;// 这句不能解决乱码的问题
// IdMessage1.ContentType := ‘text/html‘; //要增加附件就不能打开这个,要不然好像是用流发送
IdMessage1.From.address := ‘zhujq-a@glodon.com‘; // 发件人地址
IdMessage1.Recipients.EMailAddresses := ‘513187410@qq.com‘; // 收信人地址
IdMessage1.Subject := ‘标题1‘; // 邮件标题
IdMessage1.Priority := mphigh;//优先级
IdMessage1.Body.Text := ‘内容1‘;//邮件内容
TIdAttachmentFile.Create(IdMessage1.MessageParts, ‘e:\123.txt‘);//添加附件
try
IdSMTP1.Authenticate;
IdSMTP1.Send(IdMessage1);
finally
IdSMTP1.Disconnect;
end;
end;

 

===============D7=========================

procedure TForm1.Button1Click(Sender: TObject);
begin
IdSMTP1:= TIdSMTP.Create(nil);
IdSMTP1.AuthenticationType := atLogin;
IdSMTP1.Host := ‘smtp.163.com‘;
IdSMTP1.Username := ‘****************‘; //用户名
IdSMTP1.Password := ‘**************‘; //密码
IdMessage1:= TIdMessage.Create(nil);
IdMessage1.Recipients.EMailAddresses := 
‘zhujianqiangqq@163.com‘; //收件人地址(多于一个的话用逗号隔开)
IdMessage1.From.Text := 
‘zhujianqiangqq@163.com‘; //自己的邮箱地址
IdMessage1.Subject := ‘test‘; //邮件标题

idMessage1.priority:=mphigh; //优先级,mphigh为最高级
IdMessage1.Body.Text := RichEdit1.Text; //邮件内容
TIdAttachment.Create(IdMessage1.MessageParts, ‘f:\软件图.jpg‘); //添加附件
try
IdSMTP1.Connect();
try 
IdSMTP1.Authenticate;
IdSMTP1.Send(IdMessage1);
ShowMessage(‘发送成功‘);
except
ShowMessage(‘邮件发送失败‘);
end;
except
ShowMessage(‘无法连接邮件服务器!‘);
end;
IdSMTP1.Disconnect;
end;

 

发送邮件(XE10.1+WIN764)