viernes, 10 de enero de 2014

Envio de correos con Indy smtp

How do I send emails through a SMTP server that require authentication?
Previous  Top  Next

Before answering this question, we do well to state that Authentication was never in the original SMTP protocol. When RFC 821 was written in 1982, third-party SMTP servers and gateways had to relay messages between other hosts and the other hosts would act as an intermediaries between the originating SMTP servers and the intended destination. That was how E-Mail worked at the time. As time went on, the need for intermediate SMTP servers to relay messages between an originating server and a destination server faded and as the internet opened up to the general public, the capability to relay messages from a client on a different network to a destination outside of the SMTP server's network only became a security hazard that was exploited by spammers and others out to abuse E-Mail.

There are several ways that the security threat was addressed.

The SMTP server was configured to simply send mail to other networks that originated only from specific I.P. Addresses in the server's network.
The SMTP servers would require the client sending the outgoing E-Mail to authenticate by logging into the POP3 (Post Office Protocol 3) server and immediately afterwards, send the E-Mail to the SMTP server.
The third-way is by adding some extensions to the SMTP protocol that would use various Simple Authentication and Security Layer (SASL) mechanisms to ensure that the client is authorized to send outgoing E-Mail and these extensions and SASL mechanisms were formalized into standards.

Since the first two methods are relatively straightforward, we will only discuss how to use Indy's RFC 2554 support.

For Indy 8.0 and 9.0

Indy's TIdSMTP component has only limited RFC 2554 support in that it can only support one SASL mechanism called LOGIN. There are other SASL mechanisms that can be used such as CRAM-MD5, Digest MD5, Kerberos 4, GSSAPI (Generic Security Service Application Program Interface), and S/Key. Those SASL mechanisms are not supported in that version.

To use Indy's LOGIN SASL support, simply set the TIdSMTP UserName property to the username, and password property to the user's account password, and the AuthenticationType property to atLogin. Then send the E-Mail as you normally would. You can also use Indy to determine if LOGIN authentication support is available on the SMTP server and using it if it is available by using the AuthSchemesSupported property with code like this:

IdSMTP1.AuthenticationType := atNone;
IdSMTP1.Connect;
try if
   IdSMTP1.AuthSchemesSupported.IndexOf('LOGIN')>-1 then
   begin
     IdSMTP1.AuthenticationType := atLogin;
     IdSMTP1.Authenticate;
   end;
   IdSMTP1.Send(IdMessage1);
finally
   IdSMTP1.Disconnect;
end;

For Indy 10

You can use simple AUTH LOGIN similarly to Indy 9.0.  Set TIdSMTP.AuthType to atDefault.  Then set the Username and password properties in TIdSMTP.

This provided for backwards compatibility.  For many programs which are distributed to the public or on a mass scale, we recommend that you use Indy 10's SASL framework for authentication so your program can support a wide variety of SMTP servers.  Our expanded SASL framework supports TIdSMTP, TIdPOP3, and TIdIMAP4.  This framework has plug-in SASL mechanism components for CRAM (Challenge-Response Authentication Mechanism) MD5 SASL (RFC 2195), Anonymous SASL (RFC 2245), External SASL (RFC 2222), Login, One-Time-Only-Password - OTP (RFC 2444), Plain SASL (2595), and S/Key (RFC 2222).  You can also write your own SASL mechanism component by writing a descendent of TIdSASL (located in IdSASL).  To use this with framework with TIdSMTP:

1.Drop a SASL mechanism component on your form.  Those components are located on the new Indy SASL tab in the component palette.
2.In TIdSMTP, set the AuthType property to atSASL.
3.In TIdSMTP, click the button beside the SASLMechanisms property.  An editor will appear. 
4.Select the SASL mechanism components you wish to use with TIdSMTP from the available listbox. 
5.Click the RIght arrow to move those to the Assigned listbox.
6.Click Ok when you are finished.

lunes, 16 de diciembre de 2013

Copiar toda la estructura de directorio y subdirectorios desde ms-Dos

Con el comando XCopy podemos copiar una estructura de directorio completo con los parametros
/s/e/v/f/c/h/y


ejemplo: la sintaxis completa sería

DESDE_RUTA_ORIGEN:\> ccopy . RUTA_DESTINO /s/e/v/f/c/h/y


Aplicación
Hay veces que un disco duro externo está defectuoso y al navegar con el Explorador de ficheros por sus directorios no permite la navegación. Es posible que através de MS-DOS consigamos salvar estructuras de directorios a las que no podamos acceder desde Windows. Suerte.

miércoles, 11 de diciembre de 2013

Illegal PORT command Error intentando descargar de FTP


Es posible que durante el intento de descargas de un fichero desde FTP recibamos el error "Illegal Port Error" o similar. Puede producirse porque algunos ftp desestiman la conexion de equipos con ip privada enmascarada por un proxy, router .... puede solucionarse si la conexion la establecemos en modo pasivo. 

passive = true. 


martes, 26 de noviembre de 2013

Error en comando "Merge" TSQL en equipos con XP

La versión de ADO disponibles para equipos con XP no soportan el comando "Merge" y producen un error al ejecutar una consulta con dicho comando. Para evitarlo podemos añadir al comando Merge la palabra EXEC por delante de modo que quedaría algo como

"EXEC MERGE ..."

esto hace que los ADOs obvien la sintaxis ejecutandose el comando "tal cual" en servidor y evitando el error.

Esto es valido si no necesitamos "traer" datos. Para esta caso habria que aplicar algun "truco" como almacenar en la BD el resultado y posteriomente leerlo con un SELECT "normal".

Espero que sea de ayuda. A mi me ha dolido la cabeza un poco buscando solución

Me han "suprimido" las clausulas Suelo y techo

Al fin he conseguido liberarme de esa carga injusta que he soportado durante años y puedo hacer frente a una cuota asequible y "lógica" de hipoteca. Siguiendo los pasos del anterior artículo aquí expuesto, despues de batallar mucho con mi sucursal y rezachar intentos de "soborno" irrisorios. He conseguido firmar ante notario la nulidad de la clausula suelo y techo. Yo he tenido que hacerme cargo de los gastos de notaria y gestión que en mi caso han ascendido a unos 600€. (Inicialmente el banco me solicito mas de 1000€ también .. pero eso es otra película)

No dejar de reivindicar lo que os pertenece, sed insistentes (muchísimo) en vuestra sucursal y dejar claro que por mucho que nos lo vendan es un abuso. No se puede hacer super negocio con los recursos sociales.

jueves, 21 de noviembre de 2013

¿Qué es SSL?

Significado de SSL

SSL son las siglas en inglés de Secure Socket Layer (en españolcapa de conexión segura). Es un protocolo criptográfico (un conjunto de reglas a seguir relacionadas a seguridad, aplicando criptografía) empleado para realizar conexiones seguras entre un cliente (como lo es un navegador de Internet) y un servidor (como lo son las computadoras con páginas web).
Este protocolo ha sido sucedido por TLS, que son las siglas en inglés de Transport Layer Security (en español seguridad de la capa de transporte). Versiones de TLS tienen un equivalente en SSL, por ejemplo TLS 1.2 corresponde a SSL 3.3; de ahí que aún sea común que se refiera a este protocolo como SSL.

Cómo funciona una conexión con SSL, en pocas palabras

De forma básica, una conexión usando el protocolo SSL funciona de la siguiente forma:
  • El cliente y el servidor entran en un proceso de negociación, conocido como handshake (apretón de manos). Este proceso sirve para que se establezca varios parámetros para realizar la conexión de forma segura.
  • Una vez terminada la negociación, la conexión segura es establecida.
  • Usando llaves preestablecidas, se codifica y descodifica todo lo que sea enviado hasta que la conexión se cierre.

Certificado SSL

Un certificado SSL es un certificado digital de seguridad que se utiliza por el protocolo SSL. Este certificado es otorgado por una agencia independiente debidamente autorizada y es enviado por el servidor de la página web segura. El navegador de internet recibe e interpreta el contenido de dicho certificado y, al verificar su autenticidad, indica que se está realizando una conexión segura; cada navegador de internet tiene diferentes formas de indicarlo, por ejemplo un candado cerrado.

Fuente: http://aprenderinternet.about.com/od/ConceptosBasico/a/Que-Es-Ssl.htm





SSL/TLS con Delphi e INDY



 am using the indy components to implement emails in a delphi application. I am specifically using the TidSMTP component. I need to effectively support all major email servers. I use Mozilla Thunderbird as my email client and am comparing the smtp properties with those in the TidSMTP component. I have attempted to find documentation that describes the relationship between the TidSMTP properties, but have not been able to figure it out.
Can someone explain how these compare and what they do:
  • In Thunderbird:Connection Security: (None, STARTTLS, SSL/TLS).
  • In TidSMTP.UseTLS (utNoTLSSupport, utUseImplicitTLS, utUseRequireTLS, utUseExplicitTLS)
  • In Thunderbird:Authentication method: (No Authentication, Normal Password, Encrypted Password, Kerberos/GSSAPI, NTLM)
  • In TidSMTP (username, password, with useAuthentication method)
I also see other TidSMTP properties: UseEhlo, UseVerp, UseNagle. Do I need to be using these? What do they do?


When using STARTTLS, the server's listening port is initially unencrypted upon connecting. When a client connects, it can send an optional STARTTLS command to the server, if the server supports it, to dynamically perform the SSL/TLS handshake at that time. This allows legacy non-SSL/TLS clients to continue connecting to that same port, while allowing newer SSL/TLS-enabled clients to use SSL/TLS if available on the server. This corresponds to UseTLS=utUseExplicitTLS in Indy. You need to set UseEHLO to True in order to use UseTLS=utUseExplicitTLS, as the EHLO command is how TIdSMTP discovers whether the server supports the STARTTLS command or not.
When using SSL/TLS instead of STARTTLS, the server's listening port is always using encryption and the client must initiate the SSL/TLS handshake immediately upon connecting before any other data can be exchanged. This corresponds to UseTLS=utUseImplicitTLS in Indy. There is no STARTTLS command used.
For authentication, TIdSMTP has two options - the old (and unsecure) AUTH LOGIN command that is defined by the original SMTP spec, and SMTP extensions for SASL-based hashing/encryption algorithms (Kerberos, GSSAPI, NTLM, etc are implemented as SASL algorithms).
To use SASL, set TIdSMTP.AuthType to satSASL and then fill in the TIdSMTP.SASLMechanisms collection to point at separate TIdSASL-derived components for the algorithms you want to support in your app. Indy has native SASL components for DIGEST-MD5, CRAM-MD5, CRAM-SHA1, NTLM (experimental), ANONYMOUS, EXTERNAL, OTP, PLAIN, SKEY, and LOGIN (SASL wrapper for AUTH LOGIN). If you need another algorithm (Kerberos or GSSAPI, for instance), you will have to write your own TIdSASL-derived component. For algorithms that use Username/Password, the values must be assigned to a separate TIdUserPassProvider component that is then assigned to the SASL components (the TIdSMTP.UserName and TIdSMTP.Password properties are not used with SASL). The more SASL algorithms you support, the wider the number of servers you will be able to support.
For servers that still support AUTH LOGIN, it can be used either by setting TIdSMTP.AuthType to satDefault (and optionally setting TIdSMTP.ValidateAuthLoginCapability to False if the server supports AUTH LOGIN but does not report it in response to the EHLO command) and then filling in the TIdSMTP.UserName and TIdSMTP.Password properties, or by including the TIdSASLLogin component in the TIdSMTP.SASLMechanisms collection.
UseVerp and UseNagle have nothing to do with security. VERP is an SMTP extension for detecting bouncing emails due to undeliverable errors. Nagle is a networking algorithm for optimizing network data packets.

Fuente: http://stackoverflow.com/questions/10503833/what-do-the-smtp-indy-component-security-and-authentication-properties-do



martes, 19 de noviembre de 2013

Rellenar de ceros a la izquierda un numero con sql server

Supongamos que tenemos en la BD un valor de tipo entero menor que 10000 y queremos obtener el valor con el formato: 00001 (para el 1) ... 00159 (para el 159) y así para el resto. La idea sería completar por la izquierda con ceros hasta llegar al tamaño de cadena deseado en nuestro ejemplo 5 caracteres: por tanto completamos con 5 ceros. para el ejemplo del 159 quedaría 00000159 y despues quedarnos con los 5 digitos mas a la derecha de este modo tendremos los ceros necesarios para completar la cadena: 

La funcion que se encarga de repetir el cero es REPLICATE('0', NUMERO_DE_REPETICIONES). 

Con el simbolo "+" concatenamos la cadena de ceros y nos traemos de la base de datos un campo llamado "idPoint" que será tipo entero y por tanto le realizamos una conversión (o Casting) a cadena Cast(idPoint as varchar(7). 

A Todo el valor conseguido le aplicamos la funcion Right para quedarnos con los digitos que digamos empezando por la derecha.


Rellenar de ceros a la izquierda un numero con sql server

Para rellenar de ceros hacia el lado izquierdo un numero podemos hacer la siguiente instrucción sql

select x, y,  RIGHT(REPLICATE('0', 7)+ CAST(idpoint AS VARCHAR(7)), 7)

from tabla

Jesús Moreno - Ingeniero Ténico Informático - consultor Informático

Hola, soy Jesús Moreno Ingeniero Técnico Informático en sistemas por la US y propietario de éste blog. Mi trabajo en los ultimos años se ...