Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Email seend as attachment

Posted on 2000-05-15
19
Medium Priority
?
211 Views
Last Modified: 2010-04-04
I want to make a delphi (3.0 or 5.0) program that will start and open a new mailmessage in outlook express and attach a certain document as attachment and fill the mail with some standard text. (Like in MS-word File-send)

Is this easy tto setup myself or do  need a special component trhat can help me do this ?
0
Comment
Question by:RichardBorst
[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
  • 5
  • 4
  • 4
  • +3
19 Comments
 
LVL 5

Expert Comment

by:TheNeil
ID: 2810541
You can do this using various methods. The following example uses MAPI:

uses mapi;

FUNCTION SendEMail(Handle : THandle; Mail : TStrings):Cardinal;
TYPE
  TAttachAccessArray = ARRAY [0..0] OF TMapiFileDesc;
  PAttachAccessArray = ^TAttachAccessArray;
VAR
  MapiMessage : TMapiMessage;
  Receip      : TMapiRecipDesc;
  Attachments : PAttachAccessArray;
  AttachCount : INTEGER;
  iCount      : INTEGER;
  FileName    : STRING;
BEGIN
  fillChar(MapiMessage, SizeOf(MapiMessage), #0);
  Attachments := NIL;
  fillChar(Receip,SizeOf(Receip), #0);
  IF Mail.Values['to'] <> ''
  THEN
  BEGIN
    Receip.ulReserved := 0;
    Receip.ulRecipClass := MAPI_TO;
    Receip.lpszName := StrNew(PChar(Mail.Values['to']));
    Receip.lpszAddress := StrNew(PChar('SMTP:' + Mail.Values['to']));
    Receip.ulEIDSize := 0;
    MapiMessage.nRecipCount := 1;
    MapiMessage.lpRecips := @Receip;
  END;

  AttachCount := 0;
  FOR iCount := 0 TO MaxInt
  DO
  BEGIN
    IF Mail.Values['attachment' + IntToStr(iCount)] = ''
    THEN
      BREAK;
    AttachCount := AttachCount + 1;
  END;
 
  IF AttachCount > 0
  THEN
  BEGIN
    GetMem(Attachments,SizeOf(TMapiFileDesc) * AttachCount);
    FOR iCount := 0 TO (AttachCount - 1)
    DO
    BEGIN
      FileName := Mail.Values['attachment' + IntToStr(iCount)];
      Attachments[iCount].ulReserved := 0;
      Attachments[iCount].flFlags := 0;
      Attachments[iCount].nPosition := ULONG($FFFFFFFF);
      Attachments[iCount].lpszPathName := StrNew(PChar(FileName));
      Attachments[iCount].lpszFileName := StrNew(PChar(ExtractFileName(FileName)));
      Attachments[iCount].lpFileType := NIL;
    END;
    MapiMessage.nFileCount := AttachCount;
    MapiMessage.lpFiles := @Attachments^;
  END;

  IF Mail.Values['subject'] <> ''
  THEN
    MapiMessage.lpszSubject := StrNew(PChar(Mail.Values['subject']));
  IF Mail.Values['body'] <> ''
  THEN
    MapiMessage.lpszNoteText := StrNew(PChar(Mail.Values['body']));

  Result := MapiSendMail(0, Handle, MapiMessage,MAPI_DIALOG*Ord(Handle <> 0) OR MAPI_LOGON_UI OR MAPI_NEW_SESSION, 0);

  FOR iCount := 0 TO (AttachCount - 1)
  DO
  BEGIN
    strDispose(Attachments[iCount].lpszPathName);
    strDispose(Attachments[iCount].lpszFileName);
  END;

  IF assigned(MapiMessage.lpszSubject)
  THEN
    strDispose(MapiMessage.lpszSubject);
  IF assigned(MapiMessage.lpszNoteText)
  THEN
    strDispose(MapiMessage.lpszNoteText);
  IF assigned(Receip.lpszAddress)
  THEN
    strDispose(Receip.lpszAddress);
  IF assigned(Receip.lpszName)
  THEN
    strDispose(Receip.lpszName);
END;

procedure TForm1.Button1Click(Sender: TObject);
VAR
  mail : TStringList
BEGIN
  mail := TStringList.Create;
  mail.values['to']      := 'Bloke@Geeza.com';
  mail.values['subject'] := 'A subject';
  mail.values['body']    := 'Some body text (line 1)';
  mail.values['body']    := 'Some more body text (line 2)';
  mail.values['attachment0'] := 'c:\winnt\winnt256.bmp';
  mail.values['attachment1'] := 'c:\winnt\winnt.bmp';
  sendEMail(Application.Handle, mail);
  mail.Free;
END;

The Neil =:)
0
 
LVL 15

Expert Comment

by:simonet
ID: 2811533
Richard,

I've written a sample application (w/ full source code) that illustrates the usage of S-MAPI on a Delphi project.

You can download the project "How to send e-mail an faxes from a Delphi app"  from my site:
htp://www.bhnet.com.br/~simonet/howtoprojs.htm

Yours,

alex
0
 
LVL 1

Expert Comment

by:xsoft
ID: 2812114
listening...
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:sageryd
ID: 2824737
Hi all!

I think there is a much simpler way, I havn't tried it though. This is just a shot in the dark, but if you write a WinExec() proc and execute something like: "mailto:name@domain.com?Subject?Body?Attachment", it might work. I know what I just wrote is not the proper format, but if you can figure out how it's written, you might get it to work on one line of source! I know it can be done this way without attachments, I really don't know if it'll even work....

Good luck!

--johan
0
 

Accepted Solution

by:
Chawa earned 400 total points
ID: 2828437
 use this (without attach - I don't know how exactly):

  uses ShellAPI;
  ........
  ShellExecute(ValidParentForm(Self).Handle,
    'Open',
    PChar('mailto:username@somehost.com?CC=and he&BCC=and her&Subject=Text Subject&Body=Body of message',
    nil, nil, SW_SHOWNORMAL);

or Delphi components for mail
0
 
LVL 1

Expert Comment

by:sageryd
ID: 2828615
Chawa: No offense, but here at E-E we usually post comments instead of answers unless you are completely sure that there isn't somebody else that could possibly come up with a better answer than yours. So please, I think I speak for everyone when I say this, for everybody's sake, convert your answer to a comment!

Cheers! Don't take it personal!

--johan
0
 
LVL 15

Expert Comment

by:simonet
ID: 2828944
Chawa:

Read the question again. Here's some quote from it: "and attach a certain document as attachment"

How is the user supposed to attach a document using ShellExecute?


Richard,

In order to use S-MAPI with Outlook Express, you have to set it as your default MAPI application. This setting can be found in the Options dialog.

Alex
0
 

Expert Comment

by:Chawa
ID: 2828996
I don't exactly but &Attach or something else maybe!?!

 I new in expertsexhange and I send few comments, people maybe use this comments and don't send me any points.
0
 
LVL 15

Expert Comment

by:simonet
ID: 2829167
>&Attach or something else maybe
That doesn't exist.

>people maybe use this comments and don't send me any points

Get used to it. Who said life is fair? Not getting any points is much better than step in everybody's toes, isn't it?
0
 
LVL 1

Expert Comment

by:sageryd
ID: 2829170
Chawa: I E-E people are honest with each other, otherwise it wouldn't work. EEven if you propose an answer, the person who put up the question has to evaluate it, and if he/she doesn't want to give out any points for the answer he/she could just deny the answer and use it anyway. And if you post a comment the same could happen, but, you also allow other users to propose answers that may be better than yours. btw, The person who put up the Q can actually accept a comment as an answer if he/she wants to.

Simonet: I think what Chawa is trying to say is that he thinks it may be possible to send a path to a file on the HDD and let the mailprogram itself look up this file and attach it if it exists. I agree with you though on the quote, Chawa didn't exactly answer the question fully.


--johan
0
 

Expert Comment

by:Chawa
ID: 2829212
Ok. I dont think about you or anything in this question (about points). I send comments to another question, and man why ask question probably use the comment.

I am sorry about this. I only one programmer.

Thanks seqeryd.

comment to 'Who said life is fair?' is :
I from Yugoslavia and survive Bombing Attack.
0
 

Expert Comment

by:Chawa
ID: 2829233
Chawa changed the proposed answer to a comment
0
 
LVL 1

Expert Comment

by:sageryd
ID: 2829338
Well done Chawa! (Both the answer>comment, and the attack!)

:o)

--johan
0
 
LVL 15

Expert Comment

by:simonet
ID: 2843534
>RichardBorst

So, what about the e-mail stuff? Please give us some feedback on how it worked out.

Alex
0
 
LVL 15

Expert Comment

by:simonet
ID: 2925898
Alex has changed his comment from Monday, May 15 2000 - 02:16PM BRT to an answer.
0
 

Author Comment

by:RichardBorst
ID: 3276075
Comment accepted as answer
0
 

Author Comment

by:RichardBorst
ID: 3276076
I Think this coukld be the solution. I do not have working it yet but it must be a key for the solution
0
 

Author Comment

by:RichardBorst
ID: 3459487
I tried also the solution from TheNeil using MAPI.

The Neil,

Does this works with netscape's messenger.

Richard
0
 

Author Comment

by:RichardBorst
ID: 3459499
The solution from chawa workes, but not with the attachment. I tries to find the right syntax on the internet, but attachments are not supported in the "mailto"-statement.
0

Featured Post

Industry Leaders: 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

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…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

610 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