Hoặc bạn có thể sử dụng thư viện Synapse để gửi thư bằng SMTP, lý tưởng trong số newest snapshot.
Đây là mã mà nên gửi qua đường bưu điện với gắn c:\voucher.pdf
tập tin từ [email protected]
để [email protected]
đến smtp.server.com
với đăng nhập và mật khẩu login
password
. Về phần còn lại của các hàm từ lớp TMimeMess
tôi sẽ giới thiệu bạn trực tiếp đến the reference.
Tôi hy vọng điều này sẽ hiệu quả vì tôi đã đơn giản hóa và bản địa hoá mã phức tạp hơn nhiều mà tôi đang sử dụng và tôi không thể xác minh hoặc biên dịch. Nếu không, chúng ta hãy downvote nó :)
uses
SMTPSend, MIMEPart, MIMEMess;
procedure TForm.SendEmailClick(Sender: TObject);
var
MIMEText: TStrings;
MIMEPart: TMimePart;
MIMEMessage: TMimeMess;
begin
MIMEText := TStringList.Create;
MIMEText.Add('Hello,');
MIMEText.Add('here is the text of your e-mail message,');
MIMEText.Add('if you want the HTML format, use AddPartHTML');
MIMEText.Add('or e.g. AddPartHTMLFromFile if you have your');
MIMEText.Add('HTML message content in a file.');
MIMEMessage := TMimeMess.Create;
with MIMEMessage do
try
Header.Date := Now;
Header.From := '[email protected]';
Header.ToList.Clear;
Header.ToList.Add('[email protected]');
Header.CcList.Clear;
Header.Subject := 'E-mail subject';
Header.XMailer := 'My mail client name';
MIMEPart := AddPartMultipart('mixed', nil);
AddPartText(MIMEText, MIMEPart);
AddPartBinaryFromFile('c:\voucher.pdf', MIMEPart);
EncodeMessage;
if SendToRaw(Header.From, // e-mail sender
Header.ToList.CommaText, // comma delimited recipient list
'smtp.server.com', // SMTP server
Lines, // MIME message data
'login', // server authentication
'password') // server authentication
then
ShowMessage('E-mail has been successfuly sent :)')
else
ShowMessage('E-mail sending failed :(');
finally
Free;
MIMEText.Free;
end;
end;
Cập nhật:
Theo bình luận thoải mái từ Downvoter step into the light (người đàn ông, hãy thay đổi nick xin vui lòng, nó không mát nữa :), sẽ thực sự xấu nếu bạn sẽ gửi danh sách tất cả người nhận tới mọi người. Với synapse you cannot thêm BCC vào tiêu đề thư; không có tài sản Header.BCCList
trong MIMEMessage
. Thay vào đó bạn có thể trực tiếp sửa đổi dữ liệu trước khi gửi chúng.
// First, you will remove the line where you are adding a recipient to the list
Header.ToList.Add('[email protected]');
// the rest between you can keep as it is and after the message encoding
EncodeMessage;
// and before sending the mail you'll insert the line with BCCs
Lines.Insert(1, 'Bcc: [email protected], [email protected]');
if SendToRaw ...
Nguồn
2011-07-20 18:47:34
Tôi sẽ cung cấp cho tuyến đường này một shot. cc sẽ không là vấn đề. Ứng dụng chỉ gửi phiếu thưởng cho một người nhận. Chương trình tạo ra 10-15 chứng từ khác nhau và gửi email cho khách hàng của chúng tôi. Một người nhận trong toàn bộ quá trình. Việc thực hiện hiện tại bằng cách sử dụng Outlook hoạt động như một sự quyến rũ nhưng như đã nói không phải tất cả đều sử dụng triển vọng. – JamesW