delphi indy

Below are instructions for creating an "email sender" that includes an option for sending email messages and attachments directly from a Delphi application. Before we begin, consider the alternative...

以下是创建“电子邮件发件人”的说明,其中包括用于直接从Delphi应用程序发送电子邮件和附件的选项。 在开始之前,请考虑替代方案...

Suppose you have an application that operates on some database data, among other tasks. Users need to export data from your application and send the data through an email (like an error report). Without the approach outlined below, you have to export the data to an external file and then use an email client to send it.

假设您有一个对某些数据库数据进行操作的应用程序,除其他任务外。 用户需要从您的应用程序中导出数据, 通过电子邮件(例如错误报告)发送数据。 如果没有下面概述的方法,则必须将数据导出到外部文件,然后使用电子邮件客户端发送数据。

从Delphi发送电子邮件 ( Sending Email From Delphi )

There are many ways you can send an email directly from Delphi, but the simplest way is to use the ShellExecute API. This will send the email using the default email client installed on the computer. While this approach is acceptable, you're unable to send attachments this way.

您可以通过多种方式直接从Delphi直接发送电子邮件,但最简单的方法是使用ShellExecute API。 这将使用计算机上安装的默认电子邮件客户端发送电子邮件。 尽管可以接受这种方法,但是您无法以这种方式发送附件。

Another technique uses Microsoft Outlook and OLE to send the email, this time with attachment support, but MS Outlook is then required to be used.

另一种技术是使用Microsoft Outlook和OLE发送电子邮件,这一次具有附件支持,但是随后要求使用MS Outlook。

Yet another option is to use Delphi's built-in support for the Windows Simple Mail API. This works only if the user has a MAPI-compliant email program installed.

另一个选择是使用Delphi对Windows Simple Mail API的内置支持。 仅当用户安装了MAPI兼容的电子邮件程序时,此方法才有效。

The technique we're discussing here uses Indy (Internet Direct) components - a great internet component suite comprised of popular internet protocols written in Delphi and based on blocking sockets.

我们在这里讨论的技术使用Indy (Internet Direct)组件-一个很棒的Internet组件套件,包含用Delphi编写并基于阻塞套接字的流行Internet协议。

TIdSMTP(Indy)方法 ( The TIdSMTP (Indy) Method )

Sending (or retrieving) email messages with Indy components (which ships with Delphi 6+) is as easy as dropping a component or two on a form, setting some properties, and "clicking a button."

使用Indy组件(Delphi 6+附带)发送(或检索)电子邮件就像在窗体上拖放一两个组件,设置一些属性并“单击按钮”一样容易。

To send an email with attachments from Delphi using Indy, we'll need two components. First, the TIdSMTOP is used to connect and communicate (send mail) with an SMTP server. Second, the TIdMessage handles the storing and encoding of the messages.

要使用Indy从Delphi发送带有附件的电子邮件,我们需要两个组件。 首先, TIdSMTOP用于连接SMTP服务器并与之通信(发送邮件)。 其次, TIdMessage处理消息的存储和编码。

When the message is constructed (when TIdMessage is "filled" with data), the email is delivered to an SMTP server using the TIdSMTP.

构造消息后(当TIdMessage被数据“填充”时),电子邮件将使用TIdSMTP传递到SMTP服务器。

电子邮件发件人源代码 ( Email Sender Source Code )

I've created a simple mail sender project that I explain below. You can download the full source code here.

我创建了一个简单的邮件发件人项目,下面对此进行说明。 您可以在此处下载完整的源代码。

Note: That link is a direct download to the ZIP file for the project. You should be able to open it without any problems, but if you can't, use 7-Zip to open the archive so you can extract out the project files (which are stored in a folder called SendMail).

注意:该链接是直接下载到项目的ZIP文件。 您应该可以毫无问题地打开它,但是如果不能打开,请使用7-Zip打开存档,以便提取出项目文件(存储在名为SendMail的文件夹中)。

As you can see from the design-time screenshot, to send an email using the TIdSMTP component, you at least need to specify the SMTP mail server (host). The message itself needs the regular email parts filled out, like the From, To, Subject, etc.

从设计时屏幕快照中可以看到,要使用TIdSMTP组件发送电子邮件,至少需要指定SMTP邮件服务器(主机)。 邮件本身需要填写常规的电子邮件部分,例如“ 发件人” ,“ 收件人” ,“ 主题 ”等。

Here's the code that handles sending one email with an attachment:

这是处理发送带有附件的电子邮件的代码:

procedure TMailerForm.btnSendMailClick(Sender: TObject) ;
beginStatusMemo.Clear;//setup SMTPSMTP.Host := ledHost.Text;SMTP.Port := 25;//setup mail messageMailMessage.From.Address := ledFrom.Text;MailMessage.Recipients.EMailAddresses := ledTo.Text + ',' + ledCC.Text;MailMessage.Subject := ledSubject.Text;MailMessage.Body.Text := Body.Text;if FileExists(ledAttachment.Text) then TIdAttachment.Create(MailMessage.MessageParts, ledAttachment.Text) ;//send mailtrytrySMTP.Connect(1000) ;SMTP.Send(MailMessage) ;except on E:Exception doStatusMemo.Lines.Insert(0, 'ERROR: ' + E.Message) ;end;finallyif SMTP.Connected then SMTP.Disconnect;end;
end; (* btnSendMail Click *) 

Note: Inside the source code, you'll find two extra procedures that are used to make the values of the Host, From, and To edit boxes persistent, using an INI file for storage.

注意:在源代码中,您将找到两个额外的过程,用于使用INI文件存储来使HostFromTo编辑框的值持久化。

翻译自: https://www.thoughtco.com/sending-email-messages-with-attachments-1058124

delphi indy

delphi indy_使用Delphi和Indy发送电子邮件(和附件)相关推荐

  1. C# 发送电子邮件(含附件)用到的类 system.web.mail

    主要是用到了System.Web.Mail命名空间,用到了此空间的三个类,分别是: ●MailMessage类,用于构造电子邮件 ●MailAttachment类,用于构造电子邮件附件 ●SmtpMa ...

  2. sendgrid java_java – SendGrid电子邮件API,发送电子邮件附件

    我使用sendgrid发送电子邮件,使用以下代码工作正常 但它没有附件. package sendgrid; import com.sendgrid.Content; import com.sendg ...

  3. linux命令行发送串口_从命令行在Linux中发送电子邮件

    linux命令行发送串口 In this article, you will learn how to send emails using the popular mail commands. It' ...

  4. 选择 Delphi 2007 ( CodeGear Delphi 2007 for Win32 Version 11.0.2837.9583 ) 的理由

    选择 Delphi 2007 ( CodeGear Delphi 2007 for Win32 Version 11.0.2837.9583 ) 的理由 我不喜欢用InstallRite的全自动安装包 ...

  5. 亚马逊ses如何发qq_使用Amazon SES发送电子邮件

    亚马逊ses如何发qq by Kangze Huang 黄康泽 使用Amazon SES发送电子邮件 (Sending emails with Amazon SES) 完整的AWS Web样板-教程3 ...

  6. php mail函数_PHP发送电子邮件函数mail详解

    重要:本文最后更新于2019-10-09 08:49:07,某些文章具有时效性,若有错误或已失效,请在下方留言或联系代码狗. PHP作为一门使用广泛的脚本语言,经过这么多年发展已经非常完善了,发送电子 ...

  7. 如何使用PHP发送电子邮件?

    本文翻译自:How to send an email using PHP? I am using PHP on a website and I want to add emailing functio ...

  8. 如何从我的Android应用程序发送电子邮件?

    我正在为Android编写应用程序. 如何从中发送电子邮件? #1楼 简单尝试这个 public void onCreate(Bundle savedInstanceState) {super.onC ...

  9. 在Python中使用SMTP发送电子邮件

    Python中有内置的smtplib模块,完成一封邮件的发送,需要做很多准备工作.第三方的py_smtp这个包也是基于smtplib的,在Python中使用py_smtp发送电子邮件非常方便,只要填写 ...

最新文章

  1. 腾讯最大股东收购了 Stack Overflow,以后“抄代码”都要付费了么?
  2. php ip访问mysql什么配置_PHP与MYSQL配合完成IP的存取
  3. 直角三角形的边角关系_华师大版九年级第四章解直角三角形,知识点讲解加经典例题分析...
  4. pydev集成mysql_【Python】Windows平台下Python、Pydev连接Mysql数据库
  5. 数据结构实验之排序七:选课名单(卡内存的一道题。。坑)
  6. Sqli-labs less 47
  7. 转→js数组遍历 千万不要使用for...in...
  8. 为什么很多人只提苹果手机比安卓手机流畅耐用,却不提苹果手机比安卓手机贵几倍?
  9. .Net FSO简单小结(简单到不能再简单了)
  10. 【转】Visio(流程图绘制软件)的免费替代品
  11. C#中如何动态加载DockPanel
  12. 解决百度文库复制问题 非VIP也能复制文字
  13. 图像处理之边缘检测[微分算子、Canny算子和LOG算子]
  14. matlab代码:基于主从博弈的智能小区代理商定价策略及电动汽车充电管理
  15. HTML+CSS奥运五环
  16. LVM精简卷(Thinly-Provisioned Logical Volumes)的扩容
  17. 各平台安装OpenCV
  18. 基于分位数随机森林预测模型QRF建立多特征输入单个因变量输出的拟合预测模型
  19. VALSE2019总结(6)-年度总结-GAN
  20. 基于LabVIEW的电阻合格率检测装置仿真设计

热门文章

  1. R语言dplyr包group_by函数和summarise_at函数计算dataframe计算不同分组的计数个数和均值(Summarise Data by Categorical Variable)
  2. JS实现轮播图(自动+手动)
  3. 对抗攻击7——JSMA(Jacobian-based Saliency Map Attacks)
  4. 画出盒图和程序流程图
  5. 微信交易退款方法介绍
  6. 哲学 {实在论,柏拉图实在论,本体论,理型论,形式}
  7. 真题详解(哈希表)-软件设计(八十五)
  8. (每日一练C++)CC211 整数对查找
  9. Java byte转换为int
  10. 【机器学习】KNN算法实现手写板字迹识别