gpt4 book ai didi

delphi - 发送带有附件的电子邮件 与客户端无关

转载 作者:行者123 更新时间:2023-12-03 14:53:12 30 4
gpt4 key购买 nike

我目前编写了一个应用程序,可以生成 pdf 凭证并发送给潜在收件人的电子邮件。然而,我使用的功能取决于客户端(MS Outlook),我真的很想让这个电子邮件客户端不可知,因为我们有很多客户,但并非所有人都使用 Outlook。

我查看了一些选项,但在搜索中找不到任何似乎可以解决我的问题的内容。

有谁知道使用客户 smtp 连接发送电子邮件(无论客户端如何)并发送附件而无需直接调用客户端来执行此操作的好方法吗?

最佳答案

或者您可以使用Synapse库,用于使用 SMTP 发送邮件,最好在其 newest snapshot 中.

以下代码应将附带 c:\voucher.pdf 文件的邮件从 sender@from.com 发送到 recipient@to.com smtp.server.com,使用登录名 login 和密码 password。关于 TMimeMess 类中的其余函数,我建议您直接引用 the reference .

我希望这会起作用,因为我已经简化和本地化了我正在使用的更复杂的代码,但我无法验证它也无法编译。如果没有,我们就投反对票:)

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 := 'sender@from.com';
Header.ToList.Clear;
Header.ToList.Add('recipient@to.com');
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;


更新:

根据 Downvoter step into the light 的好评(伙计,请更改你的昵称,它不再酷了:),如果你将所有收件人的列表发送给每个人,那就太糟糕了。带突触 you cannot将密件抄送添加到邮件 header ; MIMEMessage 中没有 Header.BCCList 属性。相反,您可以在发送数据之前直接修改数据。

// First, you will remove the line where you are adding a recipient to the list
Header.ToList.Add('recipient@to.com');

// 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: jane@invisiblecustomer.com, lisa@invisiblecustomer.com');

if SendToRaw ...

关于delphi - 发送带有附件的电子邮件 与客户端无关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6765008/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com