KB-28661: Sending e-mails without a driver in E3 using IIS (CDO) and PowerShell.

Question:

On an application based in CDO-Collaboration Data Objects (tool developed by Microsoft to make it easier sending messages in applications)-, the IIS – Internet Information Services – is used to send e-mails without using the SendMail driver.

However, the messages are not being sent, and an error message is returned. How can I fix this problem?

Solution:

This can happen because the server being used needs authentication. So, to fix the problem, you must increment the following lines in the script that sends the e-mail:
Sub CommandButton1_Click() 
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Email's title"
objMessage.Sender = "sender@server.com"
objMessage.To = "recipient@server.com"
objMessage.TextBody = "Email's text body"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.server.com"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "send@server.com"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "user password"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
objMessage.Send
MsgBox "The e-mail was successfully sent!"
End Sub

Limitations of CDO in Modern Providers

CDO (Collaboration Data Objects) is a legacy Windows component that uses an outdated TLS implementation for secure communication with SMTP servers. Providers such as Gmail, Outlook/Hotmail, and Yahoo have discontinued support for TLS 1.0 and TLS 1.1, currently accepting only TLS 1.2 or higher. Since CDO has limited and unstable support for TLS 1.2, making it incompatible with most modern email providers, send attempts through these providers result in errors such as:

  • 0x80040217 — Server not available
  • 0x80040213 — Transport connection failed
  • 8004020E — Sender rejected by server

Alternative: Sending via PowerShell

As an alternative to CDO, it is possible to use Windows PowerShell to send e-mails directly from Elipse E3 VBScript using the WScript.Shell object.

Component Used

PowerShell uses the System.Net.Mail.SmtpClient class from the .NET Framework, which provides native support for TLS 1.2, making it compatible with the security requirements of modern e-mail providers.

Below is an example of sending an e-mail using Elipse E3:

Dim oShell
Set oShell = CreateObject("WScript.Shell")

Dim sAssunto, sCorpo, sDestinatario, sRemetente, sSenha
sRemetente    = "sender@domain.com"
sDestinatario = "recipient@domain.com"
sAssunto      = "Email subject"
sCorpo        = "Email body"
sSenha        = "senhaapp16chars"  

Dim sScript
sScript = "$smtp = New-Object System.Net.Mail.SmtpClient('smtp.gmail.com', 587);" & _
          "$smtp.EnableSsl = $true;" & _
          "$smtp.Credentials = New-Object System.Net.NetworkCredential('" & sRemetente & "', '" & sSenha & "');" & _
          "$msg = New-Object System.Net.Mail.MailMessage;" & _
          "$msg.From = '" & sRemetente & "';" & _
          "$msg.To.Add('" & sDestinatario & "');" & _
          "$msg.Subject = '" & sAssunto & "';" & _
          "$msg.Body = '" & sCorpo & "';" & _
          "$smtp.Send($msg);"

oShell.Run "powershell -NoProfile -ExecutionPolicy Bypass -Command """ & sScript & """", 0, True

Set oShell = Nothing

 


Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 5 / 5. Count: 1

Leave a Reply

Your email address will not be published.Required fields are marked *