Reputation: 597
My team is tasked with migrating a Classic ASP application from a Windows 2008 Server to a Docker container (mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019), with as little code-change as possible. The application uses Server.CreateObject("CDO.Message")
to send email.
That line, however, results in the following error: 006~ASP 0177~Server.CreateObject Failed~800401f3/
. I am given to understand from this thread, that this is because the cdosys.dll file is missing from this Windows Docker image.
It appears that the cdosys.dll file is absent in Windows Docker images, generally. I tried installing just a ton of windows features (everything .NET that was available), but none of them appear to contain this file. A team member has attempted to manually register the dll, as well, without success.
How can I use CDO.Message to send email from my Windows Docker container?
Upvotes: 0
Views: 1476
Reputation: 11
Make a wrapper class that implements the CDO.MESSAGE API.
We wrapped around System.Net.Mail
using System.Net.Mail;
using System.Runtime.InteropServices;
namespace AspClassicMail
{
[System.Runtime.InteropServices.ComVisible(true)]
[ProgId("AspClassicMail.Message")]
public class Message
{
private MailMessage mailMessage;
public string To {
get
{
return mailMessage.To.ToString();
}
set {
mailMessage.To.Clear();
mailMessage.To.Add(value.Replace(';', ','));
}
}
public string Subject {
get
{
return mailMessage.Subject;
}
set
{
mailMessage.Subject = value;
}
}
public string CC
{
get
{
return mailMessage.CC.ToString();
}
set
{
mailMessage.CC.Clear();
mailMessage.CC.Add(value.Replace(';', ','));
}
}
public string Bcc
{
get
{
return mailMessage.Bcc.ToString();
}
set
{
mailMessage.Bcc.Clear();
mailMessage.Bcc.Add(value.Replace(';', ','));
}
}
public string From
{
get
{
return mailMessage.From.Address;
}
set
{
mailMessage.From = new MailAddress(value);
}
}
public string ReplyTo
{
get
{
return mailMessage.ReplyToList.ToString();
}
set
{
mailMessage.ReplyToList.Clear();
mailMessage.ReplyToList.Add(value.Replace(';',','));
}
}
public string textbody
{
get
{
return mailMessage.Body;
}
set
{
mailMessage.IsBodyHtml = false;
mailMessage.Body = value;
}
}
public string HTMLBody
{
get
{
return mailMessage.Body;
}
set
{
mailMessage.IsBodyHtml = true;
mailMessage.Body = value;
}
}
public Message()
{
mailMessage = new MailMessage();
}
public void send()
{
SmtpClient smtpClient = new SmtpClient("YOUR MAIL SERVER");
smtpClient.Send(mailMessage);
}
}
}
You may need to include a property for "Configuration" as well. We just removed the configuration from the ASP files instead.
You can either place it in an MSI package and set the DLL class to Register "vsdrpCOM" or run RegAsm.exe from your .NET framework folder.
ASP Classic code just needs updated to replace Server.CreateObject("CDO.Message")
with Server.CreateObject("AspClassicMail.Message")
Upvotes: 1