With Delphi design can carry the attachment of the email

Source: Internet
Author: User
Tags mail connect mailmessage

Users who never use client software such as Foxmail or Outlook at ordinary times, every time the mail will be carefully open ie, hit the favorites, click on a website address, and then fill in the user name, password, add attachments, waiting for ing ..., send failed, fall back to the previous page, send again, Wait for ing ... until the sending succeeds. It's a torment to let them go through the motions every time. What can be used to ease their burden? Then add mail to your program, and don't forget to add the attachment feature (which is so useful in email) so that your users can just click once to fix everything and bring them some relief.

Will it be difficult to implement the functions mentioned above? Maybe before, but now we have the Delphi and Indy components, the development process will be like sitting in front of the window, while enjoying the scenery outside the window, while tasting the cup of coffee is generally pleasant and natural. Now let's double click Delphi to start this happy journey.

On the Delphi form, place the IDSMTP, Idmessage, OpenDialog three main components, these three components are the core components of this mail-sending program, most of the functions are implemented by them, others have some label, Labelededit and Memo components, the specific layout as shown in the following illustration:


(Figure I)

The implementation of this program is such a message, the delivery function by the Indy component to achieve, (I note: This is a very well-known for the development of the network program components, starting from Delphi6, this set of components into the Delphi built-in components, its latest version can be to http:// www.nevrona.com/indy/up to download), the IDSMTP component is used to connect and communicate with the mail server (that is, the SMTP server), while the Idmessage component is used to store and encode the contents of the message. When the message is written, the data is encoded and "populated" into Idmessage, and then joins and communicates with the SMTP server through IDSMTP.

The main code for sending mail is as follows:

Procedure Tmailerform.btnsendmailclick (Sender:tobject);
Begin
Statusmemo.clear;
Set SMTP
Smtp. Host: = Ledhost.text; The specific use of SMTP, you can apply to the mailbox on the site to find
Smtp. Port: = 25;
Set up message content
MailMessage.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 mail
Try
Try
Smtp. Connect (1000);
Smtp. Send (MailMessage);
except on E:exception do
StatusMemo.Lines.Insert (0, ' ERROR: ' + e.message);
End
Finally
If SMTP. Connected Then
Smtp. Disconnect;
End
End
Add Attachment Code
Procedure Tmailerform.btnattachmentclick (Sender:tobject);
Begin
If Attachmentdialog.execute Then
Ledattachment.text: = Attachmentdialog.filename;
End

The application of mail sending program is very extensive, with the popularization of broadband, "moment online" become possible, for your application software to join the Mail transceiver function will bring you a lot of convenience. In software development more for the sake of the user, in order to make your software really popular welcome!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.