Solved

Attaching a file to a program created email message

Posted on 2001-08-22
7
201 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
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.

775 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