...

View Full Version : Send mail in delphi with gmail using indy idsmtp



UD2006
05-21-2009, 08:56 PM
I try to send an email (with gmail) through a problem I created, but it doesnt work.

I have a form with an edit field for emailaddresses to send the email to, an edit field for subject, and an richedit field for the body message.
I use indy 10 with idsmtp component, idmessage and a IdSSLIOHandlerSocketOpenSSL1 component.

The settings of idmessage for the body should be from the richedit.lines, idmessage1.ReceiptRecipient should be edit1.text, From address I can set (gmail account), but I can't get the rest right.

I have checked the topic here: (http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_22122302.html?sfQueryTermInfo=1+10+delphi+gmail+indi+smtp)

But this didnt brought the right settings.

In the code I use I get an "error" on the object part. I think its setup wrong.
Here is the code (also from the topic up here):


unit mailsonglist1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase,
IdSMTP, IdMessage, DB, ADODB, DBCtrls, IdIOHandler, IdIOHandlerSocket,
IdIOHandlerStack, IdSSL, IdSSLOpenSSL;

type
TForm3 = class(TForm)
Label1: TLabel;
Label2: TLabel;
edtTo: TEdit;
edtSubject: TEdit;
Label6: TLabel;
Label7: TLabel;
RichEdit1: TRichEdit;
Button1: TButton;
Button2: TButton;
IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
IdSMTP1: TIdSMTP;
IdMessage1: TIdMessage;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form3: TForm3;

implementation

uses
songlisteditor1;

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
begin
idmessage1.ReceiptRecipient := edtTo.text;
idmessage1.FromList := 'songlisteditor@gmail.com';
idmessage1.Body := 'RichEdit1.lines';
idsmtp1.Connect;
idsmtp1.Send(idmessage1);
idsmtp1.Disconnect;
end;

procedure TForm3.Button2Click(Sender: TObject);
begin
edtTo.Clear;
edtSubject.Clear;
edtSubject.Clear;
RichEdit1.Clear;
end;

procedure TForm3.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
RichEdit1.Clear;
edtTo.Clear;
edtSubject.Clear;
edtSubject.Clear;
end;

end.


Form3.DFM

object Form3: TForm3
Left = 192
Top = 114
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 224
Top = 40
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object IdSMTP1: TIdSMTP
IOHandler = IdSSLIOHandlerSocketOpenSSL1
HeloName = 'csd'
Host = 'smtp.gmail.com'
Password = 'mypass'
Port = 587
SASLMechanisms = <>
UseTLS = utUseRequireTLS
Username = 'sender@gmail.com'
Left = 80
Top = 24
end
object IdMessage1: TIdMessage
AttachmentEncoding = 'MIME'
Body.Strings = (
'ceva')
Encoding = meDefault
FromList = <
item
Address = 'sender@gmail.com'
Text = 'sender@gmail.com'
Domain = 'gmail.com'
User = 'sender'
end>
From.Address = 'sender@gmail.com'
From.Text = 'sender@gmail.com'
From.Domain = 'gmail.com'
From.User = 'sender'
ReceiptRecipient.Address = 'receiver@yahoo.com'
ReceiptRecipient.Text = 'receiver@yahoo.com'
ReceiptRecipient.Domain = 'yahoo.com'
ReceiptRecipient.User = 'receiver'
Recipients = <>
ReplyTo = <>
Sender.Address = 'sender@gmail.com'
Sender.Text = 'sender@gmail.com'
Sender.Domain = 'gmail.com'
Sender.User = 'sender'
ConvertPreamble = True
Left = 120
Top = 24
end
object IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL
Destination = 'smtp.gmail.com:587'
Host = 'smtp.gmail.com'
MaxLineAction = maException
Port = 587
DefaultPort = 0
SSLOptions.Method = sslvSSLv2
SSLOptions.Mode = sslmUnassigned
SSLOptions.VerifyMode = []
SSLOptions.VerifyDepth = 0
Left = 160
Top = 24
end
end

end.


Thanks for any replies.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum