Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Attaching a file to a program created email message

Posted on 2001-08-22
7
Medium Priority
?
209 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 100 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 100 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 100 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Loops Section Overview
Suggested Courses

886 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