Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Attaching a file to a program created email message

Posted on 2001-08-22
7
Medium Priority
?
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

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!

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

715 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