How to send mail by Indy and Gmail ? (Delphi 7)

How to send mail by Indy and Gmail  ? (Delphi 7)

Thank you very much . ^_^
0
ICST
5/18/2009 7:57:01 AM
embarcadero.delphi.tools 5366 articles. 2 followers. Follow

8 Replies
1718 Views

Similar Articles

[PageSpeed] 36

> {quote:title=ICST ICST wrote:}{quote}
> How to send mail by Indy and Gmail  ? (Delphi 7)
> 
> Thank you very much . ^_^

I test successfully.

[code]
// Send mail by Gmail
//
// Delphi 7 Test OK  
//
// need OpenSSL for Delphi 7
// http://indy.fulgan.com/SSL/
// UnCompress OpenSSL file for Delphi 7, and get two files : libeay32.dll , ssleay32.dll  
// put them with Program togeter. 
  
unit Unit1;  
  
interface  
  
uses  
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  
Dialogs, XPMan, StdCtrls, IdMessage, IdTCPConnection, IdTCPClient,  
IdMessageClient, IdSMTP, IdBaseComponent, IdComponent, IdIOHandler,  
IdIOHandlerSocket, IdSSLOpenSSL;  
  
type  
TForm1 = class(TForm)  
    Button1: TButton;        // Standard  
    Button2: TButton;        // Standard  
    edtRecipients: TEdit;        // Standard  
    edtCC: TEdit;        // Standard  
    edtBCC: TEdit;        // Standard  
    edtSubject: TEdit;        // Standard  
    cbxConfirmReading: TCheckBox; // Standard  
    ListBox1: TListBox;        // Standard  
    cbxPriority: TComboBox;    // Standard  
    mmMessage: TMemo;        // Standard  
    XPManifest1: TXPManifest;    // Win32  
    odAttachments: TOpenDialog;   // Dialogs  
    IdSMTP1: TIdSMTP;        // Indy Clients  
    IdMessage1: TIdMessage;    // Indy Misc  
    IdSSLIOHandlerSocket1: TIdSSLIOHandlerSocket; // Indy I/O Handlers  
  
    procedure Button1Click(Sender: TObject);  
    procedure Button2Click(Sender: TObject);  
    procedure FormCreate(Sender: TObject);  
private  
    { Private declarations }  
public  
    { Public declarations }  
end;  
  
var  
Form1: TForm1;  
  
implementation  
  
{$R *.dfm}  
  
procedure TForm1.FormCreate(Sender: TObject);  
begin  
mmMessage.Text := '';  
Button1.Caption := 'Attach File';  
Button2.Caption := 'Send mail';  
cbxPriority.Items.Add('0');  
cbxPriority.Items.Add('1');  
cbxPriority.Items.Add('2');  
  
end;  
  
procedure TForm1.Button1Click(Sender: TObject);  
begin  
if odAttachments.Execute then  
    ListBox1.Items.Add(odAttachments.FileName);  
end;  
  
procedure TForm1.Button2Click(Sender: TObject);  
var  
xAnexo: Integer;  
begin  
  
//  IdMessage1.Recipients.EMailAddresses := edtRecipients.Text;  
IdMessage1.Recipients.EMailAddresses := '收件者Email';  
IdMessage1.From.Address := '帳號@gmail.com';  
//  IdMessage1.CCList.EMailAddresses := edtCC.Text;  
IdMessage1.CCList.EMailAddresses := '';  
//  IdMessage1.BccList.EMailAddresses := edtBCC.Text;  
IdMessage1.BccList.EMailAddresses := '';  
  
IdSMTP1.AuthenticationType := atLogin;  
IdSMTP1.Host := 'smtp.gmail.com';  
IdSMTP1.Username := '帳號';        // 不含 @gmail.com  
IdSMTP1.Password := '密碼';  
IdSMTP1.Port := 465;  
  
IdSMTP1.IOHandler := IdSSLIOHandlerSocket1;  
  
IdSSLIOHandlerSocket1.SSLOptions.Method := sslvSSLv2;  
IdSSLIOHandlerSocket1.SSLOptions.Mode := sslmClient;  
  
case cbxPriority.ItemIndex of  
    0: IdMessage1.Priority := mpLow;  
    1: IdMessage1.Priority := mpNormal;  
    2: IdMessage1.Priority := mpHigh;  
end;  
  
IdMessage1.Subject := edtSubject.Text;  
IdMessage1.Body := mmMessage.Lines;  
  
if cbxConfirmReading.Checked then  
    IdMessage1.ReceiptRecipient.Text := IdMessage1.From.Text; {Auto answer}  
  
for xAnexo := 0 to ListBox1.Items.Count - 1 do  
    TIdAttachment.Create(idmessage1.MessageParts,TFileName(ListBox1.Items[xAnexo]));  
//    TIdAttachment.Create(idmessage1.MessageParts,TFileName(ListBox1.Items.String[xAnexo]));  
  
Button2.Caption := 'Connecting...';  
  
IdSMTP1.Connect(6000);  
  
if IdSMTP1.Connected then  
begin  
    Button2.Caption := 'Connected';  
    try  
    Button2.Caption := 'Sending Message...';  
    IdSMTP1.Send(IdMessage1);  
    finally  
    IdSMTP1.Disconnect;  
    end;  
    Button2.Caption := 'Message sent successfully!';  
end  
else  
    MessageDlg('Error in Connection!',mtConfirmation,[mbOK],0);  
  
IdSMTP1.Disconnect;  
Sleep(1000);  
Button2.Caption := '&Send';  
  
end;  
  
  
end.  
[/code]
0
ICST
5/18/2009 12:51:39 PM
Hello,
I try also and it successfully send email.
But if we use internet connection with proxy setting it failed, it says "connection timeout".
What should we do with the program if we use proxy setting in the internet???

Even we use gmail with outlook, we still cannot send gmail if we use proxy setting in internet connection

Need your suggestion

> {quote:title=ICST ICST wrote:}{quote}
> > {quote:title=ICST ICST wrote:}{quote}
> > How to send mail by Indy and Gmail  ? (Delphi 7)
> > 
> > Thank you very much . ^_^
> 
> I test successfully.
> 
> [code]
> // Send mail by Gmail
> //
> // Delphi 7 Test OK  
> //
> // need OpenSSL for Delphi 7
> // http://indy.fulgan.com/SSL/
> // UnCompress OpenSSL file for Delphi 7, and get two files : libeay32.dll , ssleay32.dll  
> // put them with Program togeter. 
>   
> unit Unit1;  
>   
> interface  
>   
> uses  
> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  
> Dialogs, XPMan, StdCtrls, IdMessage, IdTCPConnection, IdTCPClient,  
> IdMessageClient, IdSMTP, IdBaseComponent, IdComponent, IdIOHandler,  
> IdIOHandlerSocket, IdSSLOpenSSL;  
>   
> type  
> TForm1 = class(TForm)  
>     Button1: TButton;        // Standard  
>     Button2: TButton;        // Standard  
>     edtRecipients: TEdit;        // Standard  
>     edtCC: TEdit;        // Standard  
>     edtBCC: TEdit;        // Standard  
>     edtSubject: TEdit;        // Standard  
>     cbxConfirmReading: TCheckBox; // Standard  
>     ListBox1: TListBox;        // Standard  
>     cbxPriority: TComboBox;    // Standard  
>     mmMessage: TMemo;        // Standard  
>     XPManifest1: TXPManifest;    // Win32  
>     odAttachments: TOpenDialog;   // Dialogs  
>     IdSMTP1: TIdSMTP;        // Indy Clients  
>     IdMessage1: TIdMessage;    // Indy Misc  
>     IdSSLIOHandlerSocket1: TIdSSLIOHandlerSocket; // Indy I/O Handlers  
>   
>     procedure Button1Click(Sender: TObject);  
>     procedure Button2Click(Sender: TObject);  
>     procedure FormCreate(Sender: TObject);  
> private  
>     { Private declarations }  
> public  
>     { Public declarations }  
> end;  
>   
> var  
> Form1: TForm1;  
>   
> implementation  
>   
> {$R *.dfm}  
>   
> procedure TForm1.FormCreate(Sender: TObject);  
> begin  
> mmMessage.Text := '';  
> Button1.Caption := 'Attach File';  
> Button2.Caption := 'Send mail';  
> cbxPriority.Items.Add('0');  
> cbxPriority.Items.Add('1');  
> cbxPriority.Items.Add('2');  
>   
> end;  
>   
> procedure TForm1.Button1Click(Sender: TObject);  
> begin  
> if odAttachments.Execute then  
>     ListBox1.Items.Add(odAttachments.FileName);  
> end;  
>   
> procedure TForm1.Button2Click(Sender: TObject);  
> var  
> xAnexo: Integer;  
> begin  
>   
> //  IdMessage1.Recipients.EMailAddresses := edtRecipients.Text;  
> IdMessage1.Recipients.EMailAddresses := '收件者Email';  
> IdMessage1.From.Address := '帳號@gmail.com';  
> //  IdMessage1.CCList.EMailAddresses := edtCC.Text;  
> IdMessage1.CCList.EMailAddresses := '';  
> //  IdMessage1.BccList.EMailAddresses := edtBCC.Text;  
> IdMessage1.BccList.EMailAddresses := '';  
>   
> IdSMTP1.AuthenticationType := atLogin;  
> IdSMTP1.Host := 'smtp.gmail.com';  
> IdSMTP1.Username := '帳號';        // 不含 @gmail.com  
> IdSMTP1.Password := '密碼';  
> IdSMTP1.Port := 465;  
>   
> IdSMTP1.IOHandler := IdSSLIOHandlerSocket1;  
>   
> IdSSLIOHandlerSocket1.SSLOptions.Method := sslvSSLv2;  
> IdSSLIOHandlerSocket1.SSLOptions.Mode := sslmClient;  
>   
> case cbxPriority.ItemIndex of  
>     0: IdMessage1.Priority := mpLow;  
>     1: IdMessage1.Priority := mpNormal;  
>     2: IdMessage1.Priority := mpHigh;  
> end;  
>   
> IdMessage1.Subject := edtSubject.Text;  
> IdMessage1.Body := mmMessage.Lines;  
>   
> if cbxConfirmReading.Checked then  
>     IdMessage1.ReceiptRecipient.Text := IdMessage1.From.Text; {Auto answer}  
>   
> for xAnexo := 0 to ListBox1.Items.Count - 1 do  
>     TIdAttachment.Create(idmessage1.MessageParts,TFileName(ListBox1.Items[xAnexo]));  
> //    TIdAttachment.Create(idmessage1.MessageParts,TFileName(ListBox1.Items.String[xAnexo]));  
>   
> Button2.Caption := 'Connecting...';  
>   
> IdSMTP1.Connect(6000);  
>   
> if IdSMTP1.Connected then  
> begin  
>     Button2.Caption := 'Connected';  
>     try  
>     Button2.Caption := 'Sending Message...';  
>     IdSMTP1.Send(IdMessage1);  
>     finally  
>     IdSMTP1.Disconnect;  
>     end;  
>     Button2.Caption := 'Message sent successfully!';  
> end  
> else  
>     MessageDlg('Error in Connection!',mtConfirmation,[mbOK],0);  
>   
> IdSMTP1.Disconnect;  
> Sleep(1000);  
> Button2.Caption := '&Send';  
>   
> end;  
>   
>   
> end.  
> [/code]
0
rudyno
9/25/2009 7:51:06 AM
> {quote:title=ICST ICST wrote:}{quote}
> How to send mail by Indy and Gmail  ? (Delphi 7)
> 
> Thank you very much . ^_^

I already developed the same application, using same features and configuration, but when using firewall mail is not able to be sent. Connection to smtp server works fine but the message is not going anywhere. 

Someone solved this issue? 

Thanks!
0
Leonardo
10/9/2009 3:52:10 PM
This is great....
Now, is there a way that the body of the email can contain graphics?  We would like a Delphi program to pop up something like a richedit window that the user can plug in some images as well as text and then send that instead of just plain text.  The images could be sent as attachments if required, but we would want them displayed in-line where the receiving email program allows.
0
Jack
10/4/2010 8:39:10 PM
<Jack Mason> wrote in message news:293974@forums.embarcadero.com...

> Now, is there a way that the body of the email can contain graphics?

Send the email contents as HTML, where it has reference to the image 
attachments.  I have articles on Indy's website for this very topic:

    HTML Messages
    http://www.projectindy.org/Sockets/Blogs/RLebeau/2005_08_17_A.EN.aspx

    New HTML Message Builder Class
    http://www.projectindy.org/Sockets/Blogs/RLebeau/20080116.EN.aspx

-- 
Remy Lebeau (TeamB)
0
Remy
10/5/2010 1:02:53 AM
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:294069@forums.embarcadero.com...

>    New HTML Message Builder Class
>    http://www.projectindy.org/Sockets/Blogs/RLebeau/20080116.EN.aspx

Note that these helper classes have been changed since the article was first 
written, and most of the shortcoming decribed (ie, no user-defined ContentID 
values) have already been addressed in later versions of Indy.

-- 
Remy Lebeau (TeamB)
0
Remy
10/5/2010 1:10:40 AM
> {quote:title=Jack Mason wrote:}{quote}
> This is great....
> Now, is there a way that the body of the email can contain graphics?  We would like a Delphi program to pop up something like a richedit window that the user can plug in some images as well as text and then send that instead of just plain text.  The images could be sent as attachments if required, but we would want them displayed in-line where the receiving email program allows.

Hi, I am a novice and need some help with Indy. When I try to compile I get the error "[Fatal Error] Unit1.pas(19): Unit IdMessage was compiled with a different version of IdEMailAddress.TIdEMailAddressList", and I suppose all other Indy components are the same.. As far as I can tell Indy 10 is installed. Can you please help me with this. Thanks
0
Lakis
8/25/2011 5:45:52 PM
<Lakis Kontos> wrote in message news:391906@forums.embarcadero.com...

> Hi, I am a novice and need some help with Indy. When I try to compile
> I get the error "[Fatal Error] Unit1.pas(19): Unit IdMessage was compiled
> with a different version of IdEMailAddress.TIdEMailAddressList", and
> I suppose all other Indy components are the same.. As far as I can tell
> Indy 10 is installed. Can you please help me with this. Thanks

You have multiple versions of Indy installed, or at least multiple versions 
of its DCUs.  You need to clean up your installation.

-- 
Remy Lebeau (TeamB)
0
Remy
8/25/2011 10:21:06 PM
Reply:

Similar Artilces:

Delphi 7 to Delphi XE
Have been using Delphi 7 for many moons ( have got later versions but never upgraded to ) My first problem is: Component Palette. in XE it is a small toolbar docked in top right in Delphi 7 it gives a large view of all the components. I am struggling to be able to cope/access my components.in Delphi XE. Can I make the component pallette tool bar the same size as Delphi 7, or is there a fast way to view/choose all available components in XE, that I have not spotted yet? Kind Regards, Robert. Hi, What I know is that in Delphi 2010 and XE you can choose between t...

Delphi 7 to Delphi XE2
Hi, Still using that old workhorse, Delphi7, but am going to the conference in London hosted by Embarcadero on Delphi XE2. Although I would like to "move with the times" and am keen to get the UNICODE and 64-bit support offered by the latest IDEs, I confess to being more than a little scared about all the UNICODE/String/AnsiString and 32/64 bit issues I'm probably going to fall over. Anyone recently upgraded from Delphi7 to one of the latest Delphi IDEs? Thanks, Alain On 03/02/2012 08:55, Alain Dekker wrote: > Still using that old workhorse, Delphi7, but...

Delphi 2007 to Delphi 7
I've written a class in Delphi 2007 that is not supported in Delphi 7. What would be the best way to achive what I've done in Delphi 2007 in Delphi 7? Thanks, Tom type BondConstants = class { Bond Types } type BondType = record const TREASURY = 3; AGENCY = 0; CORP = 1; MUNI = 2; SBA = 5; MBS = 4; CMO = 6; end; { Day Count Methods } type DayCount = record const ACTUAL_360 = 2; ACTUAL_365 = 1; ACTUAL_ACTUAL = 1; d30_360 = 0; ...

How Can I Send Email thru GMAIL Server in Delphi 7?
Hi everyone. I have Delphi 7 and the Indy components. I know that GMAIL uses ssl/tsl. I saw a posting from Marco Cantu on how to use Indy to send an email thru the gmail server. My exploration came to a screeching halt when I saw that the D7 Indy components don't have the same properties that Marco was using in his example. Does anybody have a code sample on how to send email thru this server in Delphi 7? Besides Indy, are there any third party tools that can be used for this purpose? On 2015/07/23 05:08 PM, Debbie Erickson wrote: > Hi everyone. I have Delphi 7 and the Indy co...

Indy 10 Delphi 7 Server Send Msg on button click.
Ok i have looked a a million examples and blogs, and demo's ect... but no one can tell me why i cant have the server send data to the client on a button click. I can get the client to send data on button click, I can get the server to send data on aServerExecute, and aServerConnect Both of wich are (AContext: TIdContext) where a button is (Sender: TObject), Iam guessing thats why it wont work as i would like, but I still have to belive there is a way? This is what I have soo far for server. type TClientinfo = class(TIdServerContext) public IP: String; ...

How Can I Send Email thru GMAIL Server in Delphi 7? #2
Hi everyone. I have Delphi 7 and the Indy components. I know that GMAIL uses ssl/tsl. I saw a posting from Marco Cantu on how to use Indy to send an email thru the gmail server. My exploration came to a screeching halt when I saw that the D7 Indy components don't have the same properties that Marco was using in his example. Does anybody have a code sample on how to send email thru this server in Delphi 7? Besides Indy, are there any third party tools that can be used for this purpose? at this site is a working application for Delphi 7 and the source code http://delphi.about.com...

delphi 7 Indy 9 and Indy 10
Hi, I can upgrade to indy 10 in delphi 7. But I have discover that indy 9 and Indy 10 have some different properties, so i had to change my old programs that were made in indy 9 to upgrade it to new version, but it is a long work. So I want to know if it is possible to install in the same delphi 7 both versions indy 10 and indy 9. I have tried to do it but i received a error message: Cannot load package 'IndySystem70'. It contains unit 'IdWinSock2', which is also contained in package 'Indy70'. Some can give me ideas or a link to read how to install both versi...

I wrote an application and used cracked delphi 7, after i bought delphi 7
I wrote an application and used cracked delphi 7, I sold it, after i bought delphi 7 and recompiled application, is now my application legal or? > {quote:title=Ivan Ivanov wrote:}{quote} > I wrote an application and used cracked delphi 7, I sold it, after i bought delphi 7 and recompiled application, is now my application legal or? "I embezzled some money from my employer, returned the funds, and then got it back as a bonus. Can I still be arrested?" Uhhh .... didn't you just confess to a crime? > {quote:title=Ivan Ivanov wrote:}{quote} > I wrote an appli...

Migrating from Delphi 7 to Delphi XE3
Hello, Its time to leave the old Delphi 7 and move to the new (but not the latest) XE3. I was wondering if there is a good book or reference to learn all new things XE3 added. Any suggestions? On 5/3/2013 10:17 PM, George Karatsiolis wrote: > Hello, Its time to leave the old Delphi 7 and move to the new (but not the latest) XE3. > I was wondering if there is a good book or reference to learn all new things XE3 added. Try this one for starters: http://tinyurl.com/cgsu243 Aside from that you really need to evaluate your application. XE3 is Unicode for example.... So her...

Delphi 2007 RTL in Delphi 7
I read somewhere that it is possible to use Delphi 2007's (or for that matter Delphi 2006's) RTL in Delphi 7 by just recompiling the source of RTL. Is this really possible? What are the benefits that we can derive using a higher version's RTL? TIA Yogi Yang Yogi Yang wrote: > I read somewhere that it is possible to use Delphi 2007's (or for > that matter Delphi 2006's) RTL in Delphi 7 by just recompiling the > source of RTL. If it actually compiles in Delphi 7, I guess it would be possible. OTOH, if one has Delphi 2007 already, I don't s...

Moving from Delphi 7 to Delphi 2007
Is there any compelling reason to move (quite a large project) from Delphi 7 to Delphi 2007? Specifically, is there better Vista/Win7/Win8 integration provided by Delphi 2007? (In the project I am already using a custom manifest file for Vista/Win7 etc.. and not the std XPMan component) Does 2007 add any new bugs to the scene? Thanks Rael Rael wrote: > Is there any compelling reason to move (quite a large project) from > Delphi 7 to Delphi 2007? If you are going to upgrade, why not upgrade to something newer? > In the project I am already using a custom man...

Using Delphi 7 and Delphi 2010
I had a project in Delphi 7. I worked on it in Delphi 2010. When I try to open the .dpr again in Delphi 7, the IDE toolbar widens across both monitors, and Delphi 7 locks up. It appears that Delphi 2010 modifies the .dpr in a way that makes Delphi 7 unable to open it again. All my forms & units appear to open fine in D7 after D2010, except for the warnings on the ExplicitHeight and ExplicitWidth properties being missing... I can easily recreate the .dpr, but is this expected behavior? Thanks. Tom Field wrote: > I had a project in Delphi 7. > > I worked o...

Migrating From Delphi 7 to Delphi 2010
We did not know which forum was the best for this question. We have been wanting to migrate from Delphi 7 to a later version for years but it appears to be a daunting task. We first looked at D2006 and that was a radical new world. We bought D2010 a couple of years ago and not done much with it because there are so many parts to our applications. We have done a few new applications in D2010 and they seem to work okay. D2010 has not been impressive, perhaps because of the strangeness compared to D7. Is is possible for us to do a phased sort of migration where we do a form at a time? ...

Delphi 7 to Delphi 2009 conversion
Hello group, What do I need to do to comile the following code in D2009. Compiler error after the Else E2010: Incompatible Types 'AnsiChar' and 'Char' if isUnicode then SearchHandle := FindFirstFilew( PWideChar( fn ), FindDataW ) else SearchHandle := FindFirstFile( PAnsiChar( Ansistring( fn ) ), FindDataA ); <<<<<compiler error in the above line >>>>>>>>>>> Regards, Bryan > What do I need to do to comile the following code in D2009. > Compiler error after the Else > E2010: Incompati...

Web resources about - How to send mail by Indy and Gmail ? (Delphi 7) - embarcadero.delphi.tools

Resources last updated: 11/25/2015 6:38:47 AM