Solved

Attaching a file to a program created email message

Posted on 2001-08-22
7
197 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now