Solved

Sending Email from Lotus Notes using ShellExecute

Posted on 2007-04-02
6
3,277 Views
Last Modified: 2013-12-18
Hi,
Could you please tell me how to send a email with attachment through Lotus notes using the shel execute function. my sample code works but unfortunatley doesnot handle attchments.i.e on shell execute it open the lotus notes mail sending screen but the attchmnets are not to be  found

thanks in advance
ps
below is my sample code in delphi which is suppouse to send the mail but some how the attchmnets donot come up

 var
    em_subject, em_body, em_mail,em_mailreceipient : string;
 begin
    em_subject := 'Hi there';
    em_body := 'please help with this'
    em_mailreceipient := 'richythomasv@hotmail.com'
    em_mail := 'mailto:'+em_mailreceipient+'?subject='+em_subject+'&body='+em_body
    +'&attachment='+'C:\sample1.txt';

    ShellExecute(Handle,'open',PChar(em_mail), nil, nil, SW_SHOWNORMAL) ;

Regards
richy
0
Comment
Question by:richyt
[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
6 Comments
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 18837546
Just guessing but have you tried to explicitely put " before and after your filename ?
So, instead of :
em_mail := 'mailto:'+em_mailreceipient+'?subject='+em_subject+'&body='+em_body
    +'&attachment='+'C:\sample1.txt';

use :
em_mail := 'mailto:'+em_mailreceipient+'?subject='+em_subject+'&body='+em_body
    +'&attachment='+'"C:\sample1.txt"';


I have not tested this out, but found something similar on the net.
Hope it helps.

Best regards,

Wim.
0
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 18837584
Or maybe the following link (code is VB) is a good start too :
http://www.fabalou.com/VBandVBA/lotusnotesmail.asp

You should have ComObj in your uses clause.
Also you should create an OLE-Object at runtime : CreateOleObject('Notes.NotesSession');
And then it is all in converting the methods and setting properties from VB -> Delphi.
Maybe woth a try.

Now I'm leaving home, but maybe I will try to convert the vb-code to delphi-code.

Best Regards,

Wim.
0
 
LVL 6

Accepted Solution

by:
wimmeyvaert earned 500 total points
ID: 18841750
I think I found something :

procedure SendNotesMail( ServerName, MailDbName, Subject, BodyText, Attachment, Recipient: String; SaveIt: Boolean );
var
 NotesSession: Variant;
 Database: Variant;
 Mail: Variant;
 AttachME: Variant;  { The attachment richtextfile object }
 EmbedObj: Variant;  { The embedded object (Attachment) }
begin
  NotesSession := CreateOleObject( 'Notes.NotesSession' );
  Database := NotesSession.GetDatabase( ServerName, MailDbName );
  If Not DataBase.IsOpen Then
    Database.Openmail;
  Mail := Database.CreateDocument;
  Mail.AppendItemValue( 'Subject', Subject );
  Mail.AppendItemValue( 'Body', BodyText );
  AttachME := Mail.CREATERICHTEXTITEM( 'Attachment' );
  EmbedObj := AttachME.EMBEDOBJECT( 1454, '', Attachment, 'Attachment' );
  Mail.Send( 0, Recipient );
end;


Call it like :
SendNotesMail3( 'YourServerName', 'MailFileOnDisk', 'Hi there', 'please help with this', 'C:\Sample1.txt', 'richythomasv@hotmail.com', True );

Can you try it out and let me know if it works ?

Best regards,

Wim.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 18841988
Hm, looks like it is working except that when the body contains more than 1 line of text, the mail is not sent.

I found a little workaround for that, assuming that the Body is not in a string, but in a TStrings :

procedure SendNotesMail( ServerName, MailDbName: String ; Subject, Attachment, Recipient: String ; BodyText: TStrings ; SaveIt: Boolean );
var
 NotesSession: Variant;
 Database: Variant;
 Mail: Variant;
 AttachME: Variant;  { The attachment richtextfile object }
 EmbedObj: Variant;  { The embedded object (Attachment) }
 MailBody: Variant;
 intX: Integer;
begin
  NotesSession := CreateOleObject( 'Notes.NotesSession' );
  Database := NotesSession.GetDatabase( ServerName, MailDbName );
  If Not DataBase.IsOpen Then
    Database.Openmail;
  Mail := Database.CreateDocument;
  Mail.AppendItemValue( 'Subject', Subject );
  { Instead of use AppenItemValue, use the CreateRichtTextItem-Method }
  MailBody := Mail.CREATERICHTEXTITEM( 'Body' );
  { Loop all lines of the TStrings-Parameter and add it to body, including CRLF }
  for intX:=0 to BodyText.Count-1 do
  begin
    MailBody.AppendText( BodyText[intX] );
    MailBody.AddNewLine(1); { CR/LF }
  end;
  AttachME := Mail.CREATERICHTEXTITEM( 'Attachment' );
  EmbedObj := AttachME.EMBEDOBJECT( 1454, '', Attachment, 'Attachment' );
  Mail.Send( 0, Recipient );
end;


I tested this out and it is a fully working solution.
I even included an URL in my body and I was able to click on it from my webmail !

So I guess we have found a solution to your problem.

Best regards,

Wim.
0
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 18842023
Oh yeah, and call it like (assuming that the body of the mail is in a TMemo on the Form (Memo1) :
SendNotesMail3( Server, MailDb, em_subject, 'C:\Sample1.txt', em_mailreceipient, Memo1.Lines, True );

Best regards,

Wim.
0
 

Author Comment

by:richyt
ID: 18858004
Hi ,
thanks for the info  but what i was trying to do was  not to use the Domino COM Obj. I think the mailto syntax has a problem with inline attachments.

but i found another delphi component on the net called AFQuickMail which works well  and has no problems sending the mail through any mail program be it lotus notes ,MS outlook or even out look express. this uses the MAPI Model to send the mail which i think most mail programs support

any how thanks for the COM solution i will just try it out

regards
richy


Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Suggested Courses
Course of the Month5 days, 23 hours left to enroll

627 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