sending email via Delphi

I am starting to use Delphi again after several years.
I have Delphi 2010 with the Indy components that come with it.
I want to send email from a Delphi app.
I tried using the Indy components with some code I found on-line but with no success.

Does anyone have some simple code that works well with the Indy components or know of a comprehensive email component I can buy.

Thank  you

Whitney
-1
Whitney
4/13/2015 4:05:20 PM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

3 Replies
447 Views

Similar Articles

[PageSpeed] 55

Whitney wrote:

> I tried using the Indy components with some code I found on-line
> but with no success.

What is the actual problem you are having?  What does your code actually 
look like?  There are TONS of examples floating around, please be more specific.

> Does anyone have some simple code that works well with the Indy
> components

At a bare minimum (there are, of course, more options available than just 
this):

{code}
IdMessage1.Clear;
IdMessage1.From.Address := 'me@me.com';
IdMessage1.From.Name := 'Me';
IdMessage1.Recipients.EmailAddresses := 'you@you.com';
IdMessage1.Subject := 'Hello';
IdMessage1.Body.Text := 'Hello World';

IdSMTP1.Host := 'smtp.me.com';
IdSMTP1.Port := 25;
IdSMTP1.Username := 'me';
IdSMTP1.Password := '***';

IdSMTP.Connect;
try
  IdSMTP.Send(IdMessage1);
finally
  IdSMTP1.Free;
end;
{code}

It doesn't get much simpler than this, but it can certainly be more complex 
than this, depending on your actual needs (SSL/TLS, HTML, attachments, etc).

-- 
Remy Lebeau (TeamB)
1
Remy
4/13/2015 4:27:50 PM
Thank you. I really appreciate your quick response.

Here is some more detail.

I have an application being used at a number of sites.
At each site there is a database with customer names and email addresses in a customer table.
I would like the app to be able to select names and email addresses for selected customers from the customer table and send them emails generated by the app.
When modifying the code in the the app do to this I won't know what email server or email configuration each sitesuses nor will I know if they use SSL, TLS, etc.
So I would need to add code to the app that would display a form allowing the user to assign those settings and then I would save that data  in a table to reassign each time the app is loaded.
What I don't know for sure is what all I need to ask the user for, how much of that could the app find out on its own or would the user need to enter it all ?
I basically understand the purpose of SSL and TLS but am not sure how and when to worry about that in this situation.

I tried you sample code as below and got an error the it could not connect to the host. I appreciate any help you could give on that also.

procedure TForm7.Button1Click(Sender: TObject);
begin
     IdMessage1.Clear;
IdMessage1.From.Address := 'testindyemail99@gmail.com';
IdMessage1.From.Name := 'Me';
IdMessage1.Recipients.EmailAddresses := 'whit1950@live.com';
IdMessage1.Subject := 'Hello';
IdMessage1.Body.Text := 'Hello World';

IdSMTP1.Host := 'smtp.google.com';
IdSMTP1.Port := 25;
IdSMTP1.Username := 'testindyemail99@gmail.com';
IdSMTP1.Password := 'testindy99**';

IdSMTP1.Connect;
try
  IdSMTP1.Send(IdMessage1);
finally
  IdSMTP1.Free;
end;

end;

end.
1
Whitney
4/13/2015 9:05:32 PM
Whitney wrote:

> What I don't know for sure is what all I need to ask the user for, how
> much of that could the app find out on its own or would the user need
> to enter it all ?

If you use TIdSMTP, you should be connecting to the site's own SMTP server 
and let it forward the email to each recipient as needed.  In this configuration, 
you need to know the Host/Port, Username/Password, and SSL/TLS settings of 
the site's SMTP server.  As you would be connecting to the same server every 
time, you only need to store those settings in one place, not on a per-customer 
basis.

If you use TIdSMTPRelay, it will connect directly to the SMTP server of each 
recipient, as determined by DNS lookups of the domain name of each recipient. 
 In this configuration, you only need to know the Host of the site's (or 
an external) DNS server so Indy can perform lookups as needed.  As you would 
be querying the same DNS server every time, you only need to store that setting 
in one place, again not on a per-customer basis.

> I basically understand the purpose of SSL and TLS but am not sure
> how and when to worry about that in this situation.

When using TIdSMTP, it is very important, as you need to know not only the 
port number to connect to (25, 465, 597, or custom), but also whether the 
server is expecting an explicit 'STARTTLS' command on that port.  Typically, 
ports 25 and 597 accept STARTTLS, whereas port 465 does not.  And these are 
just the standard SMTP ports, this is not accounting for custom ports the 
site might be using to deal with firewall/router policies.

> I tried you sample code as below and got an error the it could not
> connect to the host.

That is because you are connecting to the wrong Host.  You need to use 'smtp.gmail.com' 
instead of 'smtp.google.com'.  Also, on port 25, make sure that TIdSMTP.UseTLS 
is set to either utNoTLSSupport (no SSL/TLS) or utUseExplicitTLS (STARTTLS, 
in which case you need to assign an SSLIOHandler component, such as TIdSSLIOHandlerSocketOpenSSL, 
to the TIdSMTP.IOHandler property before calling Connect()).

-- 
Remy Lebeau (TeamB)
1
Remy
4/13/2015 9:49:21 PM
Reply:

Similar Artilces:

How to send email using Delphi?
In the past, I used Jedi MAPI wrapper, but it won't work in Unicode Delphi where I get "General MAPI failure" " TmpEmail := TjclEmail.Create; TmpResolve := False; try TmpResolve := TmpEmail.ResolveName(TmpStr_Name, TmpStr_Email, True); except // new code for Delphi unicode... Also gives mapi failure end; if TmpResolve then TmpEmail.Recipients.Add(TmpStr_Email) else TmpEmail.Recipients.Add('smtp:' + TmpStr_Email) ; TmpEmail.Recipients[0].Name := TmpEmail.Recipients[0].Address; TmpEmail.Subject := 'bla bla...

Delphi and Delphi for .Net
It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. I would like to know is it true all .Net application is slower than Win32 native applicaiton or it is Delphi for .Net only. Your information is great appreciated, Inung On 2011-06-21 18:20:17 +0100, Inung Huang said: > It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. > I would like to know is it true all .Net application is slower than > Win32 native applicaiton or it is Delphi for .Net only. If you are only running the code in the application once then, yes, yo...

sending emails with attachement delphi 2009
Hi, I have a problem, I'm using delphi 2009, I made a small application that uses TIdsmtp to send mails, for attachments I'm using TIDAttachmentFile class, like with TIdAttachmentFile.Create(IdMessage1, 'c:\image1.jpg') do begin ContentType := 'image/jpeg'; FileName := 'image1.jpg'; end; SMPT.send(IdMessage1); If I dont use attachment it works fine, but with attachemtns I'm getting email with some dummy name for attachemnt like ATI1284765.dat (if I change file extension to jpg it's ok then, it's that pictu...

What is the best way to send email within the delphi
Hello everybody. I have to prepare an email with attachment.(1 file everytime). I dont know sender and recipient. My client have Outlook 2000-2003-2007. My aim is to populate a new email screen with an attachment. Then user will select recipients then pust the send button of the outlook. I tried with ShellExecute(handle,'open', 'mailto:&Attachment=""C:\1.txt""',nil,nil, SW_SHOWNORMAL ); but cant attach the file in Outlook 2007. While reading at the internet, I saw that shellexecute is not enough in Outlook 2003. Is there any way to do ...

Sending email attachments through Outlook from Delphi programmatically
Is there some option that has to be set to allow this? I'm using ICS and it works fine for the email, but the attachment doesn't arrive. If I send to Outlook Express client, the attachment arrives. I'm sending through the same Exchange server to both clients. TIA -- -----Jon----- Am 29.01.2010 20:46, schrieb Jon Springs: > Is there some option that has to be set to allow this? > > > I'm using ICS and it works fine for the email, but the attachment doesn't > arrive. If I send to Outlook Express client, the attachment arrives. >...

Sending email w/ attachments with Delphi 2?
Does anyone know if there is a version of Indy or any other component that would enable an application written with Delphi 2 to send email with attachments? The references I've come up with just report problems and limitations with it so I'm wondering if anyone knows of something more likely to work. I'm afraid you have to look here: http://gohistoric.com/places/318695 Maybe you take a higher Delphi version and create a DLL with the functionality you want. Use the DLL in your Delphi 2 application. > {quote:title=Philip Caracena wrote:}{quote} > Does anyone know if t...

Delphi 2009 - incompatibile with 2006
Hi I was working on D2006 for a long time. I made a litle email client using INDY. When I open this projekt on new D2009 sending function won't work. The program become frozen on line "SMTP.Send(MailMessage);" Do you know what I have to do? Here is this function: function sendus(const typ,kn,tresc:pchar): boolean; stdcall; var smtp: tidsmtp; MailMessage: TIdMessage; ssl: tIdSSLIOHandlerSocketOpenSSL; begin result := true; ssl:= tIdSSLIOHandlerSocketOpenSSL.create; MailMessage := TIdMessage.Create; smtp := tidsmtp.Create; ssl.SSLOptions.Met...

SEPA components for Delphi with Source Code (Delphi 5
Hi all, in the european union change next year the Bankingformat to the SEPA Format. All peoples and companies must change the bankingssoftware and the costumer data form acountnummers in the new IBAN and BIC numbers. See: http://www.arma-it.de/shop/artikelueber.php?wgruppeid=211&wgruppe_offen=211 Functions: - generate SEPA XML'S - Calc IBAN - BIC Database (DE,AT and CH) Questions: vertrieb@arma-it.de PS: Bankinssoftware for Develpoers (Germany only) http://www.arma-it.de/shop/artikelueber.php?wgruppeid=212&wgruppe_offen=212 El 26/10/13 21:38, A...

Delphi 4 to Delphi 2009
Hello, Thanks to all who answered my previous question. That was a great help. And atlast our client agreed to upgrade our delphi version from 4 to Delphi 2009. *Sigh*. But before that, I need to give the estimation and cost regarding the migration to delphi 2009. Can anyone tell me is there any tool to migrate from delphi 4 to delphi 2009 or just I need to compile our Delphi 4 application in Delphi 2009. I have read from the delphi 2009 feature matrix that Delphi 1 through Delphi 2007 import is possible in delphi 2009. But i am not that sure considering the size of our application. ...

delphi.general
Sorry if this is "out of topic"! but since some days ago I can't read the group *embarcadero.public.delphi.language.delphi.general* Does anybody know if there's something wrong with it? Or maybe is my reader? (Thunderbird) I get this messagge when I try to read the latest messages: Error! newsgroup server responded:no such article found Perhaps the article has expired <692702@forums.embarcadero.com> (33145) Click here to remove all expired articles sergio wrote: > Sorry if this is "out of topic"! but since some days ago I can'...

Delphi for PHP or Delphi PRISM
Hi, I have the opportunity to develop a web-based library management system. Nothing fancy, just being able to do the usual CRUD stuff for books and provide a search facility. Borrowing is to be done via an email request to the library admin who then sends out the book(s). Since both Delphi for PHP and Delphi PRISM will enable me to develop the app, which one will allow me to deliver it in less time and also increase (even how small) my marketability as a web developer? Thanks. Phillip Flores Phillip Flores wrote: > Hi, > > I have the opportunity to develop a...

Problems sending emails with attachments in Indy SMTP in Delphi 2009
Hi, I'm working with Delphi 2009 fully updated (12.0.3420.21218 with Update Pack 3), and I had the original version of the Indy 10.2.5. All attachments were going with a file name ATT000043.dat, instead of the correct name. I updated to the latest Indy from the Dev Snapshot, and it went to version 10.5.7. However, now the attachment does not appear as an attachment at all, the the message appears as: This is a multi-part message in MIME format --HF2WOHttwwLp1TZg=_wwY6H2qbRC0RDTyU Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Content-Disposition: inline H...

Delphi 4 to Delphi 2007
Hello, I will have to port a D4 application (with source) to D2007. what kind of problem could I face ? I will have to go to customer site tommorow to analyse its source code to quote the work, what should I care of to hestimate the porting time ? Thanks John Terry wrote: > Hello, > I will have to port a D4 application (with source) to D2007. > what kind of problem could I face ? > I will have to go to customer site tommorow to analyse its source code > to quote the work, what should I care of to hestimate the porting time ? You can probably do it by just changi...

Delphi 5 to Delphi 6 and up
Dear List, Trying to add 7Zip compression support to my delphi application. I am using the ported 7Zip sdk (see their website, they have a link). I am stumped on how to rewrite a single function: function ReverseDecode(var Models: array of SmallInt; ....): ..... where the input is mostly a fixed size array of SmallInt. This code perfectly compiles and functions in Delphi 6 and up, but in Delphi 5 I get the error: There is no overloaded version of 'ReverseDecode' that can be called with these arguments And obviously, the input (fixed) isn't the same as the param de...

Web resources about - sending email via Delphi - embarcadero.delphi.general

Sending/receiving relationship - Wikipedia, the free encyclopedia
A sending/receiving relationship is one in which a public school district sends some or all of its students to attend the schools of another ...

U.K. Woman Faces 20 Months For Creating Fake Facebook Accounts, Sending Herself Abusive Messages
A woman in Cornwall in the U.K. came up with a creative way to use Facebook to accelerate a family spat, and it earned her 20 months in prison. ...

CHVRCHES - Dear guys, Please stop sending us emails like... - Facebook
Dear guys, Please stop sending us emails like this. This is one of the more polite ones. Other recent classics include "I'm going to give her ...

[...] Facebook Prevents Users From Sending Suspicious Friend Requests To Strangers, Inside Facebook [...] ...
Facebook has begun implementing new security measures to prevent friend request spamming. Some users are being shown a “This Request Can’t Be ...

A better experience for sending Tweets and DMs - Twitter Blog
... panel New Tweet panel in da...... Skip to main content Blog Got an account? Sign in Search form Search &nbsp A better experience for sending ...

How to Go From Working 60 Hours a Week to 40 By Sending 2 Emails a Week
I’m convinced 95% of cubicle workers who work over 60 hours a week constantly can cut it down to 40-45 hours by sending 2 emails a week to their ...

Emoticon and Emoji Box for iPhone -Save Emoticons,emoji,pic and images for Sending Message! 200 FREE ...
Get Emoticon and Emoji Box for iPhone -Save Emoticons,emoji,pic and images for Sending Message! 200 FREE emoticons and emojis - on the App Store. ...

Thanks for sending an iPhone4 and Sim T-Mobile but ... - Flickr - Photo Sharing!
... that's probably not going to work. (also, I'm sticking with the iPod touch).

Texas Man Makes $10K A Month Sending Potatoes With Personalized Messages In The Mail! - YouTube
Alex Craig, 24, said he came up with the idea for Potato Parcel earlier this year while having dinner with his girlfriend. His girlfriend called ...

'It was scary': widow speaks out as Muslim cleric pleads guilty to sending offensive letters to families ...
The young widow of fallen Australian soldier Brett Till still recalls the fear that came after she opened a letter sent to their home that labelled ...

Resources last updated: 12/26/2015 7:06:23 PM