我看了其他的相关资料仍无法解决的问题,邮件还是无法发出去!
代码如下:
var
MyMail:TIdMessage;
begin
try
SendUserName:=Copy (Edit_FromAddress.text,1,Pos('@',Edit_FromAddress.text) -1);
with MyMail do
begin
Subject:=Edit_MailTitle.Text;
// Body:=Memo_Body.Lines;//<--有问题
Recipients.EMailAddresses:=Edit_ToAddress1.Text;
From.Address:=Edit_FromAddress.Text;//<--有问题
ReceiptRecipient.Text:='';
end; if IdSMTP.Connected then IdSMTP.Disconnect; IdSMTP.Host := Edit_SmtpHost.Text;
IdSMTP.Port:=25;
IdSMTP.UserName := SendUserName;
IdSMTP.Password := Edit_FromUserPwd.Text; IdSMTP.AuthenticationType := TAuthenticationType(true);
IdSMTP.Connect; IdSMTP.Authenticate; IdSMTP.Send(MyMail);//<--有问题
MessageBox(handle,'邮件发送成功!','恭喜您...',Mb_Ok+Mb_Iconinformation);
except
MessageBox(handle,'邮件发送失败!','警告...',Mb_Ok+Mb_IconWarning);
end;
代码如下:
var
MyMail:TIdMessage;
begin
try
SendUserName:=Copy (Edit_FromAddress.text,1,Pos('@',Edit_FromAddress.text) -1);
with MyMail do
begin
Subject:=Edit_MailTitle.Text;
// Body:=Memo_Body.Lines;//<--有问题
Recipients.EMailAddresses:=Edit_ToAddress1.Text;
From.Address:=Edit_FromAddress.Text;//<--有问题
ReceiptRecipient.Text:='';
end; if IdSMTP.Connected then IdSMTP.Disconnect; IdSMTP.Host := Edit_SmtpHost.Text;
IdSMTP.Port:=25;
IdSMTP.UserName := SendUserName;
IdSMTP.Password := Edit_FromUserPwd.Text; IdSMTP.AuthenticationType := TAuthenticationType(true);
IdSMTP.Connect; IdSMTP.Authenticate; IdSMTP.Send(MyMail);//<--有问题
MessageBox(handle,'邮件发送成功!','恭喜您...',Mb_Ok+Mb_Iconinformation);
except
MessageBox(handle,'邮件发送失败!','警告...',Mb_Ok+Mb_IconWarning);
end;
Body:=Memo_Body.Lines;//<--有问题
其中Memo_Body.Lines应该是邮件体,你是否按协议来写的。你可以从OutLook中复制一段邮件体来试一下
C:\Program Files\Borland\Delphi6\Demos\Indy\MailClient下不是用很完整的例子吗???