Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 25th, 2005, 07:29 AM
derrickatdev derrickatdev is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 464 derrickatdev User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 27 sec
Reputation Power: 8
ShellExecute and Emailing

Hi,

I can create and send email messages from my Delphi program. But I can't retain new lines and paragraphs in the message body. Heres the code (modified code from delphi.about.com)

Code:
procedure TfrmOffers.btEmailClick(Sender: TObject);
var
  em_subject, em_body, em_mail : string;
begin
 em_subject := 'Test from within Delphi';
 em_body := 'Trying to send a message from the Delphi version of the Program.' + chr(13) + chr(10) + chr(13) + chr(10) + 'Should be a new paragraph.';

 em_mail := 'mailto:derrick@domain.com?subject=' +
 em_subject + '&body=' + em_body ;

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


This is a very peice of code to test the process. It simply assignes text to strings and uses the default email program you've set for Windows. It works correctly except that the chr(13) + chr(10) are lost when the ShellExecute command is used!

Does anyone know why?

Thankx
__________________
:-)

Last edited by derrickatdev : January 25th, 2005 at 07:35 AM.

Reply With Quote
  #2  
Old January 26th, 2005, 12:15 AM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Click here for more information.
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,713 Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 11 h 21 m 11 sec
Reputation Power: 1179
Can you use the SMTP component instead. Is there a good reason why you need this to be sent by the default mail program. Also try enclosing your body string within double quotes.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month

Reply With Quote
  #3  
Old January 26th, 2005, 12:54 PM
tinyabs tinyabs is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 93 tinyabs User rank is Private First Class (20 - 50 Reputation Level)tinyabs User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 13 h 24 m 34 sec
Reputation Power: 4
PHP Code:
 I can create and send email messages from my Delphi programBut I can't retain new lines and paragraphs in the message body. Heres the code (modified code from delphi.about.com) 


What email program are u using?

Perhaps you can pass a .eml file as a cmd parameter. Not sure which program support this.

Reply With Quote
  #4  
Old January 27th, 2005, 03:15 AM
derrickatdev derrickatdev is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 464 derrickatdev User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 27 sec
Reputation Power: 8
Hi,

The idea is to use any emailing program that Windows has set as the default. There would be no point in creating a method for individual programs.

I still haven't fount an answer to this problem and for now I'm going with sending emails from within the Delphi program.

I've shamlessly used some code from:
http://delphi.about.com/od/internetintranet/l/aa020304a.htm
This seems to be working really well so far.

I'd still like to get the Windows default emailing program problem solved but for the moment I've had to comtinue with other stuff.

Bye

Reply With Quote
  #5  
Old January 27th, 2005, 11:00 AM
tinyabs tinyabs is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 93 tinyabs User rank is Private First Class (20 - 50 Reputation Level)tinyabs User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 13 h 24 m 34 sec
Reputation Power: 4
Try UrlEncode on the body to encode CrLf.

Reply With Quote
  #6  
Old January 28th, 2005, 08:41 AM
derrickatdev derrickatdev is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 464 derrickatdev User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 27 sec
Reputation Power: 8
Hi,

Thanks tinyabs, that seems to work so far, just changing the characters #13, #10 and & (so far).

I still have a problem in that the ShellExecute command requires the string you're passing to be converted to PChar which means that is the string is over 255 characters it stops working! Anyone know of a way around this as some of the emails sent from my program are going to be very large.

Bye

Reply With Quote
  #7  
Old January 28th, 2005, 04:57 PM
FriendlyPenguin FriendlyPenguin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 16 FriendlyPenguin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m
Reputation Power: 0
Indy's component seems to get things flagged as spam.

Reply With Quote
  #8  
Old February 2nd, 2005, 02:43 PM
robixmundo robixmundo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 14 robixmundo User rank is Private First Class (20 - 50 Reputation Level)robixmundo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 h 45 m 24 sec
Reputation Power: 0
Wath about this?
That's not my code, I found it on Internet two months ago, but I don't remeber who and where! Therefore, it uses mapi unit, and you can send attachments too.
Following constants are myself defined

SM_OK
SM_NOTGTADDR
SM_NOSNDADDR

but you can use yours return values....


function SendEMail( const TargetName, TargetAddr,
SenderName, SenderAddr,
MsgSubject, MsgContent,
Attachment : String;
PreviewMsg : Boolean = TRUE ) : Integer;
var
msg : TMapiMessage; // Message pointer
mrdSender, // Sender
mrdTarget : TMapiRecipDesc; // Receiver
mfdAttach : TMapiFileDesc; // Attachemets
liFlags : Longint; // Flags for MAPI.
begin
liFlags := 0;
fillChar( msg, sizeOf( msg ), 0 );
with msg do
begin
if TargetAddr = '' then
begin
Result := SM_NOTGTADDR;
exit;
end
else
begin
if TargetName = '' then
mrdTarget.lpszName := pChar( TargetAddr )
else
mrdTarget.lpszName := pChar( TargetName );
mrdTarget.ulRecipClass := MAPI_TO;
mrdTarget.lpszAddress := pChar( TargetAddr );
mrdTarget.ulReserved := 0;
mrdTarget.ulEIDSize := 0;
mrdTarget.lpEntryID := nil;
nRecipCount := 1;
lpRecips := @mrdTarget;
end;

if {SenderAddr = ''}FALSE then
begin
Result := SM_NOSNDADDR;
exit;
end
else
begin
if SenderName = '' then
mrdSender.lpszName := pChar( SenderAddr )
else
mrdSender.lpszName := pChar( SenderName );
mrdSender.ulRecipClass := MAPI_ORIG;
mrdSender.lpszAddress := pChar( 'SMTP:' + SenderAddr );
mrdSender.ulReserved := 0;
mrdSender.ulEIDSize := 0;
mrdSender.lpEntryID := NIL;
lpOriginator := @mrdSender;
end;

lpszSubject := pChar( MsgSubject );
lpszNoteText := pChar( MsgContent );

if Attachment = '' then
begin
nFileCount := 0;
lpFiles := nil;
end
else
begin
fillChar( mfdAttach, sizeOf( mfdAttach ), 0 );
mfdAttach.nPosition := cardinal( $FFFFFFFF );
mfdAttach.lpszPathName := pChar( Attachment );
nFileCount := 1;
lpFiles := @mfdAttach;
end;
if previewMsg then liFlags := MAPI_DIALOG;
result := SM_OK - mapiSendMail( 0, application.Handle, msg, liFlags, 0 );
end;
end;
Comments on this post
thaminda agrees!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > ShellExecute and Emailing


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT