miércoles, abril 24, 2024

Envio de correo por Microsoft Exchange desde .Net

Descargar solución EnvioCorreoWindows_Exchange.zip

Algo muy importante es identificar la direccion del Servidor Exchange y poseer permisos para enviar correos, osea tener un usuario registrado para la debida autenticación.

Para autenticar con el servidor debemos indicarle el protocolo

Fields.Add(» http://schemas.microsoft.com/cdo/configuration/smtpauthenticate», «2») ‘; ‘basic authentication

Más explicitamente el mensaje sería:

Dim email As New MailMessage

With email
.From = Me.txtDe.Text
.To = Me.txtPara.Text
.Subject = Me.txtAsunto.Text
.Body = Me.txtMensaje.Text
.BodyFormat = MailFormat.Text
.Priority = MailPriority.High

If Me.rbExchange.Checked Then
.Fields.Add("http://schemas.microsoft.com/cdo/" & _
"configuration/smtpauthenticate", "2") 'authentication
Else

.Fields.Add("http://schemas.microsoft.com/cdo/" & _
"configuration/smtpauthenticate", "1") 'authentication
.Fields.Add("http://schemas.microsoft.com/cdo/" & _
"configuration/sendusername", Me.txtPOP3User.Text) 'usuario
.Fields.Add("http://schemas.microsoft.com/cdo/" & _
"configuration/sendpassword", Me.txtPOP3Pass.Text) 'password
End If
End With

SmtpMail.SmtpServer = Me.txtExchangeServer.Text

SmtpMail.Send(email)

Descargar solución EnvioCorreoWindows_Exchange.zip

Roy Rojas
Roy Rojashttp://www.dotnetcr.com
Con más de 20 años de experiencia en programación, experto en lenguajes .NET, VB, C#, ASP.NET, Xamarin, XCode, DBA en SQL Server. Creador de dotnetcr.com, sitio web para programadores en español. royrojas.com | dotnetcr.com | GitHub
Roy Rojas
Roy Rojashttp://www.dotnetcr.com
Con más de 20 años de experiencia en programación, experto en lenguajes .NET, VB, C#, ASP.NET, Xamarin, XCode, DBA en SQL Server. Creador de dotnetcr.com, sitio web para programadores en español. royrojas.com | dotnetcr.com | GitHub