Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Formatting default message in email

Posted on 2004-10-19
11
Medium Priority
?
198 Views
Last Modified: 2010-04-05
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;
0
Comment
Question by:rincewind666
  • 4
  • 4
  • 2
  • +1
11 Comments
 

Author Comment

by:rincewind666
ID: 12350967
Nearly forgot.  I am using Delphi 6.  Many thanks for your help.
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 2000 total points
ID: 12351411
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
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 12355256
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12355417
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
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 12356924
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
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 12357029
and also not bad to take a look here :
http://delphi.about.com/library/weekly/aa020304a.htm
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 12358028
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
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 12358886
EddieShipman , but what about other smtps , ex yahoo , aol or ...
is it possible to send an email to those without SMTP ?
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 12360270
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 12360302
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
 

Author Comment

by:rincewind666
ID: 12373060
Many thanks for your help.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

916 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