Board index » delphi » Here, I am useing from this script for sending mail, but it fail !

Here, I am useing from this script for sending mail, but it fail !


2008-05-13 03:56:30 PM
delphi112
i passed error "530 Must issue a STARTTLS command first" by
using TIdSSLIOHandlerSocketOpenSSL,
but what now:
SMTPStatus event say, 'connected' but nothing happen after that,
what is wrong?
here is my script(is this script work or not):
i realy need your help,
procedure TForm1.btmSendMailClick(Sender: TObject);
begin
mStatusLogger.Clear;
//setup mail message
MailMessage.From.Text := 'XXXX@XXXXX.COM';
MailMessage.Recipients.EMailAddresses := 'XXXX@XXXXX.COM';
MailMessage.Subject := 'Mail Subject';
MailMessage.Body.Text:='Hello';
if FileExists(edtAttFile.Text) then
TIdAttachmentFile.Create(MailMessage.MessageParts, OpenDialog1.FileName);
SMTP.AuthType := atDefault;
SMTP.UseTLS := utUseExplicitTLS;
SMTP.Username := 'XXXX@XXXXX.COM';
SMTP.Password := 'mypass';
{General setup}
SMTP.Host := 'smtp.gmail.com';
SMTP.Port := 25;
{now we send the message}
SMTP.Connect;
try
try
SMTP.Send(MailMessage);
except on E:Exception do
mStatusLogger.Lines.Insert(0, 'ERROR: ' + E.Message);
end;
finally
SMTP.Disconnect;
end;
end;
 
 

Re:Here, I am useing from this script for sending mail, but it fail !

"Delphi Lover" <XXXX@XXXXX.COM>writes
Quote
SMTPStatus event say, 'connected' but nothing happen after that,
what is wrong?
There is no way to diagnose that without more information, such as a trace
log from a packet sniffer.
Quote
MailMessage.Body.Text:='Hello';

if FileExists(edtAttFile.Text) then
TIdAttachmentFile.Create(MailMessage.MessageParts,
OpenDialog1.FileName);
That is not the correct way to set up TIdMessage. If you put an attachment
into the MessageParts, then you have to put the text into the MessageParts
as well. ou are also not setting the ContentType property at all. For
example:
if FileExists(edtAttFile.Text) then
begin
with TIdText.Create(MailMessage.MessageParts, nil) do
begin
Body.Text := 'Hello';
ContextType := 'text/plain';
end;
TIdAttachmentFile.Create(MailMessage.MessageParts, edtAttFile.Text);
MailMessage.ContextType := 'multipart/mixed';
end else
begin
MailMessage.Body.Text := 'Hello';
MailMessage.ContextType := 'text/plain';
end;
Alternatively, if you are using Indy 10.2.3, have a look at the
TIdMessageBuilderHTML class, ie:
with TIdMessageBuilderHtml.Create do
try
Subject := 'Mail Subject';
PlainText.Text := 'Hello';
if FileExists(edtAttFile.Text) then
Attachments.Add(edtAttFile.Text);
FillMessage(MailMessage);
finally
Free;
end;
Quote
SMTP.Host := 'smtp.gmail.com';
SMTP.Port := 25;
Have you read this article yet?
Send mail to GMail using Indy
www.marcocantu.com/tips/oct06_gmail.html
Gambit