var
idattachment: TIdAttachment
begin
Result:= false
try
Msg.Clear
Msg.Body.Add(RzMemo1.Text) //邮件内容
Msg.From.Text:= RzEdit7.Text//副标题
Msg.From.Name:= RzEdit3.Text//发件人
Msg.Subject:= RzEdit4.Text //标题
Msg.Recipients.EMailAddresses := RzEdit2.Text// 发送者地址
if RzEdit5.Text <>'' then
idattachment:= tidattachment.Create(Msg.MessageParts, RzEdit5.Text)
SMTP.AuthenticationType:=atLogin
SMTP.Host:= RzEdit6.Text
SMTP.Username:= RzEdit7.Text
SMTP.Password:= RzEdit8.Text
SMTP.Port := 25
SMTP.Connect
SMTP.Send(Msg)
SMTP.Disconnect
except
on E: Exception do
begin
Application.MessageBox(Pchar('发送邮件失败:' + E.message), 'szy', MB_OK or MB_ICONINFORMATION)
SMTP.Disconnect
exit
end
end
Application.MessageBox(Pchar('发送邮件成功!'), 'szy', MB_OK or MB_ICONINFORMATION)
Result:= true
end
---------------------------
Msg.Recipients.EMailAddresses 的地址用''分隔就行了,也就是memo里的收件人地址用分号分隔
使用 delphi 来实现发邮件功能,通常使用 IdSmtp 控件,以下是参考代码:
procedure TForm1.Button1Click(Sender: TObject)begin
SMTP.Host:='smtp.163.com' //邮件服务器地址
smtp.Username:='用户名@163.com' //用户名
smtp.Password:='密码'
smtp.Port:=25 //邮件服务器端口
smtp.Connect()
MgeSend.Recipients.EMailAddresses:= '[email protected]' //收件人地址
MgeSend.From.Text :='[email protected]'
MgeSend.Subject :='test' //邮件主题
MgeSend.Body.Text:='发邮件测试' //邮件内容
SMTP.Authenticate
Smtp.Send(mgeSend)
end
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)