Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to send an email through Delphi

Status
Not open for further replies.

minckle

Programmer
Mar 17, 2004
142
0
0
GB
I need to be able to send an email through Delphi with a couple of requirements.

Im using Delphi v5.

Requirement 1 - its important that the email is sent directly from delphi and does not load Outlook(or equivalent) in any way.

Requirement 2 - No history of the email sent should be saved in outlook(or equivalent).

I realise you can use ShellExecute / mailto, but when i try all the examples on the net it brings the email up in Outlook and then saves the emails in your sent items. Is there a way to send it automatically from delphi.

thanks



 
Easy...

Make sure you have the JVCL installed ( and use the JvMail component...

JvMail1.Recipient.AddRecipient('email@mail.com', 'Mr. Smith');
JvMail1.Subject := 'My Subject';
JvMail1.Body.Append(txtMESSAGE.Text);
JvMail1.SendMail(True);

There are many more properties, but this should get you started.

Paul

Paul Wesson, Programmer/Analyst
 
Try the Indy components: TIdSMTP and TidMessage

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-"There is always another way to solve it, but I prefer my way.
 
Hi thanks 4 your help

I've installed Indy components, but when i run a example i get the following error. could you shed any light on where i am going wrong.

Error: Project1.exe raised exception class EIdProtocolReplyError with message'5.7.1 Unable to relay for m.inckle@btinternet.com. Process stopped.

Code:
SMTP.host := 'localhost';
SMTP.Port := 25;

//setup mail message
MailMessage.From.Address := 'matt@softwareskills.co.uk';
MailMessage.Recipients.EMailAddresses := 'm.inckle@btinternet.com';

MailMessage.Subject := 'aaaa';
MailMessage.Body.Text := 'aaaa';

//send mail
try
try
SMTP.Connect(1000);
SMTP.Send(MailMessage);
except on E:Exception do
showmessage('Error');
end;
finally
if SMTP.Connected then
SMTP.Disconnect;
end;
 
I have used the ICS componets to do this, but there is a lot of overhead, and stuff to know to use these properly. I dont know if the Indy components are the same. But the Jedi component would seem to be excellent, if that is all that is involved.


[red]GNBM 4th Feb[/red] More on and other neat UK stuff at forum1091
Steve: Delphi a feersum engin indeed.
 
Minckle,

Indy & code is ok.
are you running a local smtp server?

if not, you must point the SMTP.host towards one that can relay the email for you...

Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
I've downloaded Indy and every thing seems to be working ok. The next stage would be to send a formatted email, i.e an email using different fonts/colours/sizes. Is this possible? I've changed the Content type to 'text/html' but it doesnt seem to work as easy as that.

Any 1 got any thoughts?
 
If you want to send an email as HTML, then you need to construct the email as you would any HTML page i.e.
Code:
<html>
  <head>
    <style>
      <!-- formatting of html tags goes here -->
    </style>
  </head>
  <body>
    <!-- content goes here -->
  </body>
</html>
If you have Outlook on your computer, locate an HTML email you have received, right-click the content area of the email, select "View Source" from the pop-up menu. This will give you a clue as to how to do it.

If you don't know HTML very well, then visit W3 Schools

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Hi thanks I've got that working now, the only problem is - how do i convert what a users types into a RichText Editbox into HTML?? will there be a downladable convertor?
 
Check out this page: (scroll to the bottom of the page for an answer.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top