delphi and GMAIL... a sample

Giganews Newsgroups
Subject: delphi and GMAIL... a sample
Posted by:  fabio codebue @ gestionaleopen (fabio.codeb…@gestionaleopen.org)
Date: Sat, 10 Apr 2010

I'm very tired to try it...

I can't find a solution.... I wrote this code.... it seems work but noone mail wanna leave my pc...

  //setup SMTP
  server_SMTP.Host := arc.utn.FieldByName('USER_HOST').AsString;
  if arc.utn.FieldByName('PORTA_SMTP').AsInteger > 0 then
  begin
  // standard 465
    server_SMTP.Port := arc.utn.FieldByName('PORTA_SMTP').AsInteger;
  end
  else
  begin
    server_SMTP.Port := 25;
  end;

  //  server_smtp.username :=  arc.utn.fieldbyname('descrizione').asstring + ' <' +
  //    arc.utn.fieldbyname('user_id').asstring + '>';

  server_smtp.username := arc.utn.fieldbyname('user_id').asstring;
  server_smtp.password := arc.utn.fieldbyname('user_password').asstring;

  IdSSLIOHandlerSocketOpenSSL.Host := arc.utn.FieldByName('USER_HOST').AsString;
  //IdSSLIOHandlerSocketOpenSSL.Port:= arc.utn.FieldByName('PORTA_SMTP').AsInteger;
  IdSSLIOHandlerSocketOpenSSL.Port := server_SMTP.Port;
  server_SMTP.IOHandler := IdSSLIOHandlerSocketOpenSSL;

  //  server_SMTP.SASLMechanisms:= ;
  server_SMTP.UseTLS := utNoTLSSupport;

  // Login type
  if arc.utn.fieldbyname('AUTENTIFICAZIONE_SERVER_SMTP').asstring <> 'SASL' then
  begin
    server_SMTP.AuthType := atDefault;
  end
  else
  begin
    server_SMTP.AuthType := atSASL;
    // SSL
    if arc.utn.fieldbyname('RICHIESTO_SSL').asstring = 'si' then
    begin
      IdSSLIOHandlerSocketOpenSSL.Host := arc.utn.FieldByName('USER_HOST').AsString;
      IdSSLIOHandlerSocketOpenSSL.Port := arc.utn.FieldByName('PORTA_SMTP').AsInteger;
      server_SMTP.IOHandler := IdSSLIOHandlerSocketOpenSSL;
    end;
  end;

  iduserpassprovider.username := arc.utn.fieldbyname('user_id').asstring;
  iduserpassprovider.password := arc.utn.fieldbyname('user_password').asstring;

  //setup mail message
  v_mail := TIdMessage.Create(nil);
  v_mail.UseNowForDate := true;
  v_mail.Priority := mpHighest;

  //  mittente
  if arc.utn.FieldByName('mittente_mail').AsString <> '' then
  begin
    v_mail.From.Address := arc.utn.fieldbyname('mittente_mail').asstring;
  end
  else
  begin
    v_mail.From.Address := arc.utn.FieldByName('user_e_mail').AsString;
  end;
  if arc.utn.fieldbyname('descrizione_utente_mail').asstring = 'si' then
  begin
    v_mail.From.Address := arc.utn.fieldbyname('descrizione').asstring + ' <' + v_mail.From.Address + '>';
  end;

  //  destinatario
  if arc.utn.FieldByName('mittente_mail').AsString <> '' then
  begin
    v_mail.Recipients.EMailAddresses := arc.utn.FieldByName('mittente_mail').AsString;
  end
  else
  begin
    v_mail.Recipients.EMailAddresses := arc.utn.FieldByName('user_e_mail').AsString;
  end;

  v_mail.bcclist.EMailAddresses := lista;

  v_mail.replyto.emailaddresses := arc.utn.fieldbyname('user_e_mail').asstring;
  v_mail.Subject := v_oggetto.Text;
  v_mail.Body.Add(v_messaggio.Lines.Text);

  //  allegati
  if v_lista_allegati.items.count > 0 then
  begin
    for i := 0 to v_lista_allegati.items.count - 1 do
    begin
      lista_puntatore := v_lista_allegati.items[i].data;
      tidattachmentfile.create(v_mail.messageparts, lista_puntatore.allegato);
    end;
  end;

  //send mail
  try
    try
      server_SMTP.ConnectTimeout := 15000;
      server_SMTP.Connect;
      server_SMTP.Send(v_mail)
    except on E: Exception do
        //
    end;
  finally
    if server_SMTP.Connected then
      server_SMTP.Disconnect;
  end;
  v_mail.MessageParts.Clear;

do you have any idea?
or do you have a sample to send a email using smtp.gmail.com?

thanks in advance

Replies