[英]How to use CDO.Message to send email in Classic ASP from Windows Docker IIS 2019
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.我的团队的任务是将经典 ASP 应用程序从 Windows 2008 服务器迁移到 Docker 容器 ( mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019 ),代码更改尽可能少。 The application uses
Server.CreateObject("CDO.Message")
to send email.应用程序使用
Server.CreateObject("CDO.Message")
发送 email。
That line, however, results in the following error: 006~ASP 0177~Server.CreateObject Failed~800401f3/
.但是,该行会导致以下错误:
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.我从这个线程中了解到,这是因为这个 Windows Docker 图像中缺少 cdosys.dll 文件。
It appears that the cdosys.dll file is absent in Windows Docker images, generally.通常,Windows Docker 图像中似乎不存在 cdosys.dll 文件。 I tried installing just a ton of windows features (everything .NET that was available), but none of them appear to contain this file.
我尝试只安装大量 windows 功能(所有可用的 .NET),但它们似乎都不包含此文件。 A team member has attempted to manually register the dll, as well, without success.
一名团队成员也尝试手动注册 dll,但未成功。
How can I use CDO.Message to send email from my Windows Docker container?如何使用 CDO.Message 从我的 Windows Docker 容器发送 email?
Make a wrapper class that implements the CDO.MESSAGE API.制作实现 CDO.MESSAGE API 的包装器 class。
We wrapped around System.Net.Mail我们围绕 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.
我们只是从 ASP 文件中删除了配置。
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. 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")
只需更新 ASP Classic 代码即可将
Server.CreateObject("CDO.Message")
替换为Server.CreateObject("AspClassicMail.Message")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.