Formatting default message in email

When the user clicks a button, their email program opens with the recipients email address, subject and message already filled out.  Unfortunately, the message is all on 1 line - I want it broken up into paragraphs as originally in "message.txt".

I have found the following code elsewhere in this forum but how can I get the message nicely formatted?



var
Buffer : String;
recip,subj,mess : String;
begin
recip:= EmailEdit.text;   {message recipients email address}
subj:='Your script: ' + FolderLabel.Caption;     {message subject}

//  Load message
Memo1.Clear;
if FileExists(ExtractFilePath(Application.ExeName) + 'message.txt') then
begin
PublishForm.Memo1.Lines.LoadFromFile(ExtractFilePath(Application.ExeName) + 'message.txt');
end;

Mess:= Memo1.Text;    {message}
Buffer:='mailto:'+recip+'?subject='+subj+'&body='+mess;
ShellExecute(Application.Handle,'open',PChar(Buffer),nil,nil,SW_Normal);
Sleep(500);              {give mail prog time to open}
keybd_Event(VK_MENU, 0, 0, 0);  {get email prog menu}
keybd_Event(ord('S'), 0, 0, 0);  {s for send}
keybd_Event(ord('S'), 0, KEYEVENTF_KEYUP, 0); {click}
keybd_Event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);  {exit menu}
Memo1.Clear;
end;
rincewind666Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Eddie ShipmanConnect With a Mentor All-around developerCommented:
Using Mailto is not the prefered way of handling default emails.

Besides, using those keybd events, how do you know that they are
correct for all email clients?

My suggestion is to use SimpleMAPI. try Mike Shkolnik's MAPIMail components here:
http://www.scalabium.com/mapimail.htm
0
 
rincewind666Author Commented:
Nearly forgot.  I am using Delphi 6.  Many thanks for your help.
0
 
Amir AzhdariCommented:
rincewind666,
EddieShipman is right ,
anyway if you are only interested to use that way yet , ok you can try your code with these changes  :

Regards
Amir

procedure TForm1.Button1Click(Sender: TObject);
var
Buffer : String;
recip,subj,mess : String;
i:integer;
begin
recip:= EmailEdit.text;   {message recipients email address}
subj:='Your script: ' + FolderLabel.Caption;     {message subject}

//  Load message
Memo1.Clear;
if FileExists(ExtractFilePath(Application.ExeName) + 'message.txt') then
begin
Memo1.Lines.LoadFromFile(ExtractFilePath(Application.ExeName) + 'message.txt');
end;

//Mess:= Memo1.text;    {message}
mess:='';
for i:=0 to memo1.lines.count-1 do
mess:=mess+memo1.lines.Strings[i] +'%0d%0a';


Buffer:='mailto:'+recip+'?subject='+subj+'&body='+mess;
ShellExecute(Application.Handle,'open',PChar(Buffer),'','',SW_showNormal);
Sleep(500);              {give mail prog time to open}
keybd_Event(VK_MENU, 0, 0, 0);  {get email prog menu}
keybd_Event(ord('S'), 0, 0, 0);  {s for send}
keybd_Event(ord('S'), 0, KEYEVENTF_KEYUP, 0); {click}
keybd_Event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);  {exit menu}
Memo1.Clear;
end;
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
Wim ten BrinkSelf-employed developerCommented:
Anyway, I would mark an application with this kind of behaviour as a trojan just because it tries to send an email by using my mail application without permission. And I would notice it too since my mail program uses very different shortcut keys. Even worse, my email program would just store the email until I explicitly tell it to send all emails. And I will check what is in my out box.
But another flaw here is that a sleep(500) might not even be enough. It could be that the whole mail application still has to load and you have no way of checking if it's running already, including the message screen... No, you will have to use an alternative instead. Either include your own SMTP client code in this application (Indy can do this easily) or use the MAPI interface to send the email. You can even just add a new email to Outlook by interfacing with the Outlook components. Then all you need to do is just add the message to Outlook and Outlook will send it.
But even then you might have a problem. I have multiple email accounts and again, a non-outlook email application that does not have a default sender option. If this email would manage to get sent, it lacks the sender information and will thus bounce at my ISP. (I've tried! It bounces.)

So not only is this piece of code suspicious enough for me to actually wipe whatever application it is part of from my disk, it also might not work in many situations...
0
 
Amir AzhdariCommented:
rincewind666,
if you are using Delphi6 then you can also try with TNMSMTP in Fastnet tab
let me know if you want more about that and i'll sendyou a sample code

by the way as Workshop_Alex  other way is trying with indy components
0
 
Amir AzhdariCommented:
and also not bad to take a look here :
http://delphi.about.com/library/weekly/aa020304a.htm
0
 
Eddie ShipmanAll-around developerCommented:
Oh, please, AmirAzhdari, NEVER suggest anyone to use the Netmasters components. They are extremely buggy and haven't been updated since 1996.

I have another option if you want to send email without the user knowing it.

The article I wrote about access Hotmail with Delphi was written as a basis for a sort of program support system. I didn't want to ask the user any
questions about their smtp settings, users or passwords.

In this scenario, I create a Hotmail account, then use the techniques outlined in the article to have the application send me an email using MY OWN
Hotmail account. This way, the user deosn't even have to know it happened and I don't have to fuss with SMTP.

Read the article here:
http://www.delphipages.com/news/detaildocs.cfm?ID=137 (part 1)
http://www.delphipages.com/news/detaildocs.cfm?ID=138 (part 2)

Download the article files here:
http://www.delphipages.com/result.cfm?ID=4615

If you need help getting it working, you can contact me at mr_delphi_developer at yahoo dot com
0
 
Amir AzhdariCommented:
EddieShipman , but what about other smtps , ex yahoo , aol or ...
is it possible to send an email to those without SMTP ?
0
 
Eddie ShipmanAll-around developerCommented:
Yahoo!, yes, see YahooPops on sourceforge: http://sourceforge.net/projects/yahoopops/

It is essentially a POP3/SMTP proxy that you can hook up any smtp/pop3 email client to
access Yahoo email.

AOL, you must use SMTP to send email TO AOL;
AOL has a proprietary system so you can not send using
an AOL account without their browser.

I intended to modify my article to access Yahoo! as well but didn't have time. I worked on it
for well over a year. Microsoft changed security models in the middle of writing the article
and the code no longer worked. I didn't find out until several months afterwards why. It has
to do with the trusted site thing that I check for in the code. I am also about 50% finished
with a component that you can drop on your form that will handle the Hotmail stuff just as
in the article.

I am also working on a GMail account access system for Delphi but it is in initial planning stages.
0
 
Eddie ShipmanAll-around developerCommented:
Problem with YahooPops is that you'd have to install it on the user's system and modify their smtp settings to access it.
YahooPops is essentially a "screen scraper" for Yahoo! mail because Yahoo! doesn't have an "API" so to speak.

Hotmail uses WebDAV so it has a standard to follow, even though M$ has modified it to their own tastes.

You can take the same techiniques in YahooPops and apply them to a Delphi program if you are willing to
sift through how it's done. If I had the time, I'd do it. I know how it works and how to do it in Delphi, just taking
the time to do it is the key...
0
 
rincewind666Author Commented:
Many thanks for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.