Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

E-mailing an attachment file from Delphi 2

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
How easy is it to compose a Delphi application that allows the user to send an attached file to a recipient through their e-mail client. Ideally all they should do is indicate the e-mail address and the file path of the attachment as required.
Is this easily done ?
Does this require their e-mail client to be open for something like this to operate ?
Thanks in advance.
Steve
 
uses
ShellAPI

procedureForm1.Button1Click(Sender: TObject);
begin
ShellExecute(Self.Handle, nil,'mailto: email@address.com', nil, nil, SW_NORMAL);
end;
 

Will launch your e-mail client with the address specified but thats it!.

Most of the simple 3rd party mail handlers do only that as well, If any does know of a simple way to do this AND set up an attachment, I would like to know as well.

Steve.
 
Steve,

Delphi provides a MAPI unit that makes this relatively trivial. I've just posted a simple example using Simple MAPI (an old approach, but fairly broadly supported) to
Now, my example is simple, but it illustrates the basic technique. A more modern approach would use the newer interface object provided MAPI. For more information on those, please see the Help file titled "Microsoft Win32 Messaging (MAPI) Reference." This should have been installed with your copy of Delphi.

Also, if you have the Professional or Enterprise editions of Delphi and have installed the source files, it may be helpful to review the source of the MAPI unit located in source/rtl/Win/mapi.pas.

Hope it helps...

-- Lance
 
Well, this is indeed a lot of code,
one could use the TNmSmtp component from the FastNet tab of the component palette (D4 & D5) or an equivalent comp in D6.
Just fill in a few properties, add some filename(s) to attachements, and with Connect, SendMail, DisConnect the mail is sent.

HTH
TonHu
 
TonHu,

It does, but I avoided those approaches for the following reasons:

1. The FastNet components are notoriously problematic and have had licensing questions associated with them from time to time.

2. A lot of people I've talked to haven't gone to D6 yet. Also, SteveK didn't indicate which version he was using, so I pulled the most common.

I picked Simple MAPI because a) it's supported by nearly all versions of Delphi and b) most people have (by now) MAPI-compliant email agents.

As I said in the article, "there are several approaches available." As they say in Perl, "There Is More Than One Way To Do It." :)

Choose the one that best fits your needs.

-- Lance

P.S. Besides, I hardly think ~80 lines of code is "a lot" Again, YMMV.


-- Lance

 
Thanks for the advice and the pointer to your page (and sample code) for this issue. I'm going to spend some time looking at it shortly but it looks like it might be of great help to me.
Thanks again.
Steve
 
I've tried the application and keep getting the error message
"The following recipient(s) could not be reached:
'emailaddres@address.com' on 01/02/02 10:40
No transport provider was available for delivery to this recipient."
We use Microsoft Outlook 2000.
Any thoughts ?
 
StevenK,

Not immediately sure. Let's take it into email and then summarize the results here in a follow-up.

-- Lance
 
StevenK,

Still awaiting to hear from you to get this fixed. Email address is on the original page.

-- Lance

 
Sorry I didn't get back to you - been out of town. :)
Anyway was actually able to resolve the issue - the code you pointed me to seems to operate OK when I use my OutLook Express at home - but didn't when I was running OutLook from the office. I've now dug some code off the net which allows me to use OutLook so I now have the answer for both situations.
Much appreciated for your help with this.
Steve
 
Steven, can you tell where one can get this additional code ?

When I try to send mails with SendMail I get also the message
"... No transport provider was available for delivery to this recipient."
I'm using Outlook 98.

Roderich
 
Riderich,

Are you using Windows 95, 98, or ME? If so, have you updated Windows Messaging?

If not (or if you're not sure), get a copy of EXUPUSA.EXE from Microsoft's site. Note that you might need to uninstall Windows Messaging first.

Links and some relevant details can be found at
While the article was written for a different problem, I think the the same idea applies.

Hope this helps...

-- Lance
 
hi Lance

thank you for the tip with "EXUPDUSA.EXE".
I got it from Microsoft, but it seems to be an update for Windows 95 only. I'm using Windows 98 SE and Outlook 98, so I didn't install it. Microsoft warns not to install an older version over newer files.

I've noticed a strange behaviour of SendMail: When I check "Preview message before sending" my Outlook shows the mail. Now clicking on "Send" would bring the above error ("... No transport provider was available..."). But when I enter the same EMail adress manually and then hoose "Send", it works !

Any idea ?

Regards
Roderich
 
Roderich,

It works for Windows 98 as well. (It's what I used to write that article I pointed you to.)

Note: I haven't tested it under Windows ME, though. If someone could do that and send me an email (at the address shown on my profile), I'd appreciate it.

Also, I do not expect that update to be appropriate for Windows NT, 2K, or XP users.

If you send the message without previewing, is it delivered? If so, then try modifying the code in the library to only prepend SMTP to the target email address only when PreviewMsg is true. Let me know if that works. (I use a different MTA, so can't try it myself.)

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top