|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
PHP Code:
What email program are u using? Perhaps you can pass a .eml file as a cmd parameter. Not sure which program support this. |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
Try UrlEncode on the body to encode CrLf.
|
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
Indy's component seems to get things flagged as spam.
|
|
#8
|
|||
|
|||
|
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; |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > ShellExecute and Emailing |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|