Solved

Formatting default message in email

Posted on 2004-10-19
11
192 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 500 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
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.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 103
indy Tmemory stream non latin charcter issue 2 121
Delphi XE10 Round Image 2 154
SUM 2 INTEGER ARRAYS INTO 1 10 108
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

789 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