procedure TForm1.Button2Click(Sender: TObject);
var
tmp:string;
begin
with IdMessage1 do
begin
Clear; // 清除前一次產生的 body & headerm, 以免第二次按時重複
Body.Assign(Memo1.Lines);
From.Text := 'yangtang_newton@163.com'; // 寄件者
Recipients.EMailAddresses := 'yangtang_newton@163.com'; // 收件者
Subject := 'subject 主題';
//Priority := TIdMessagePriority(2); // 0-4, 0表示最高優先順序
//CCList.EMailAddresses := 'a@a.com;b@b.com';
//BccList.EMailAddresses := 'd@d.com;e@e.com';
ReceiptRecipient.Text := '';
// ReceiptRecipient.Text := From.Text; //若要寄件回函,改成這行
end;
// 附加的檔案
// TIdAttachment.Create(IdMessage1.MessageParts, 'c:/t1.zip');
// TIdAttachment.Create(IdMessage1.MessageParts, 'c:/t2.zip');
//SMTP server 認證的方式
// IdSMTP1.AuthenticationType := atNone; // 不用認證,要認證改為下面三行
IdSMTP1.AuthenticationType := atLogin; {Simple Login}
IdSMTP1.UserId := 'yangtang_newton';
IdSMTP1.Password := '????';
//一般設定
IdSMTP1.Host := 'smtp.163.com';
IdSMTP1.Port := 25;
//寄送
try
IdSMTP1.Connect;
try
IdSMTP1.Send(IdMessage1);
ShowMessage('E-Mail 已寄出');
finally
IdSMTP1.Disconnect;
end;
except
on e: exception do
begin
ShowMessage('Mail 寄送失敗:' + e.Message);
end;
end;
end;