Solved

Attaching a file to a program created email message

Posted on 2001-08-22
7
203 Views
Last Modified: 2010-04-06
I cannot seem to create an email with an attachment from my Delphi programs. Has anyone done this? If anyone has the code for this I would greatly appreciate it.
0
Comment
Question by:JohnMoshis
7 Comments
 
LVL 6

Accepted Solution

by:
edey earned 25 total points
ID: 6416251
Perhaps these links will help:

http://www.scalabium.com/faq/dct0049.htm (with outlook)
http://www.scalabium.com/faq/dct0115.htm (with MAPI clients)

Also, I belive that the indy components not only come with pop3 & smtp components, but the demo pack should have an example of sending attachements (http://www.nevrona.com/indy)

GL
Mike
0
 
LVL 3

Assisted Solution

by:rondi
rondi earned 25 total points
ID: 6416754
check out Francois Piette's free ICS package.
iT's got wickid SMTP components, & attachments are quite
straightforward.

Download 'em from http://www.rtfm.be/fpiette

rondi.
0
 
LVL 1

Assisted Solution

by:Phoenix_s
Phoenix_s earned 25 total points
ID: 6429507
ok.. here we go... this allows one or more attachments to be sent to one or more recipients.


procedure below REQUIRES comobj unit in the uses list.



procedure emailattachment(sendto, subject: string; body: tstrings; attachment:string);

const // for email capability
  olFolderDeletedItems = $00000003;
  olFolderOutbox = $00000004;
  olFolderSentMail = $00000005;
  olFolderInbox = $00000006;
  olFolderCalendar = $00000009;
  olFolderContacts = $0000000A;
  olFolderJournal = $0000000B;
  olFolderNotes = $0000000C;
  olFolderTasks = $0000000D;
  olMailItem = 0;

var str1, str2, str3 : string;
    pos1 : integer;
    outlook, nmspace, folder, mailitem: olevariant;


begin

  try
    outlook := getactiveoleobject('outlook.application');
  except
    outlook := createoleobject('outlook.application');
  end;


  nmspace := outlook.getnamespace('MAPI');
  nmspace.logon(emptyparam, emptyparam, false, true);
  mailitem := outlook.createitem(olmailitem);
  //parse recipients
  pos1 := pos(';',sendto);
  if pos1 = 0 then
    mailitem.recipients.add(sendto)
  else
    begin
      str3 := sendto;
      repeat
        str1 := copy(str3,1,pos1-1);
        str2 := copy(str3,pos1+1,(length(str3)-length(str1)));
        mailitem.recipients.add(str1);
        str3 := str2;
        pos1 := pos(';',str3);
      until pos1 = 0;
      mailitem.recipients.add(str3);
    end;
  mailitem.subject := subject;
  mailitem.body := body.text;
  //process attachments
  str1 := ''; str2 := ''; str3 := '';
  pos1 := pos(';',attachment);
  if pos1 = 0 then
    mailitem.attachments.add(attachment)
  else
    begin
      str3 := attachment;
      repeat
        str1 := copy(str3,1,pos1-1);
        str2 := copy(str3,pos1+1,(length(str3)-length(str1)));
        mailitem.attachments.add(str1);
        str3 := str2;
        pos1 := pos(';',str3);
      until pos1 = 0;
      mailitem.attachments.add(str3);
    end;

  mailitem.send;
  nmspace.logoff;
  nmspace := unassigned;
  mailitem := unassigned;
  outlook := unassigned;
end;

to use this procedure you need to set up a couple things

sendto contains semicolon delimited recipient names

subject contains the email subject

body is a stringlist created and populated with email text

attachment contains semicolon delimited filenames (full path required)

then call emailattachment(sendto,subject, body,attachment)  to send it off
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:Phoenix_s
ID: 6445853
JohnMoshis:

it's been a while since you've responded to this Q.

have you tried any suggestions at all yet?
0
 

Author Comment

by:JohnMoshis
ID: 6446768
I have tried them and a combination of them solved the problema. Thanks to everyone who helped on this.
0
 
LVL 1

Expert Comment

by:Phoenix_s
ID: 6477897
JohnMoshis:

are you going to allocate points and give them out for this question??
0
 
LVL 17

Expert Comment

by:geobul
ID: 9288034
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

split points among edey, rondi and Phoenix_s

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 78
creating threads in delphi 1 157
Create a path if not exists 7 105
Delphi: Connect to running MS Outlook 4 156
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question