如何使用 C# 在正文中使用微软发布者发送电子邮件

发布于 2024-08-22 13:00:09 字数 112 浏览 4 评论 0原文

嗨,我有一个新要求。如何在邮件正文中发送新闻通讯。

该新闻通讯是由 Microsoft Publisher 应用程序制作的。

如果您需要更多信息,请告诉我。

谢谢

Hi I have a new requirement. How can I send a newsletter in the body content in a mail .

The newsletter is made from Microsoft Publisher application.

Kindly let me know if you need more info.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离不开的别离 2024-08-29 13:00:09

拉克兰·罗奇(Lachlan Roche)有一个很好的答案。
我想补充一点,您可能会考虑输出时事通讯
Adobe Acrobat、图像文件或 html。

大多数新闻通讯的目标用户可能都没有安装 Publisher。
因此,向他们发送 .pub 文件可能不会达到预期的效果。

我假设您的客户希望能够在其中调用宏或 Office 应用程序
出版商将他们撰写的时事通讯作为电子邮件发送给人员列表。

Lachlans 代码将让您发送电子邮件,我建议添加一个导出步骤
时事通讯采用更通用的格式。我相信你可以利用内置的
从您的导出代码中调用 Publisher 中的函数。

Lachlan Roche has an excellent answer.
I would just add that you might think about outputting the newsletter
to Adobe Acrobat, or an image file, or html.

Most people targeted by the newsletter probably will not have Publisher installed.
so sending them the .pub file might not have the desired effect.

I presume your client wishes to be able to envoke a Macro or Office App inside of
Publisher to send the newsletter they have composed as an email to list of people.

Lachlans code will let you send the email, I am suggesting adding a step to export
the newsletter to a more universal format. I am sure you can leverage built in
functions in Publisher from your code for the export.

恋你朝朝暮暮 2024-08-29 13:00:09

要在 .NET 中发送电子邮件,请使用 SmtpClient 和 MailMessage附件类。

MailMessage 类表示邮件消息的内容。 SmtpClient 类将电子邮件传输到您指定用于邮件传递的 SMTP 主机。您可以使用 Attachment 类创建邮件附件。

假设您有一份带有单独样式表和图像的 HTML 新闻通讯,您需要创建一个带有 HTML 正文内容的 MailMessage 并将外部文件添加为附件。您需要设置每个附件的 ContentId 属性,并更新 HTML 中的引用以使用它。

附件 HTML 正文中的 href 使用 cid: 方案。对于 ID 为“xyzzy”的附件,href 为“cid:xyzzy”。

要构造带有 HTML 正文的 MailMessage:

        string content; // this should contain HTML

        // Create a message and set up the recipients.
        MailMessage message = new MailMessage(
           "[email protected]",
           "[email protected]");

        message.Subject = "The subject.";
        message.Body = content;
        message.IsBodyHtml = true;

要构造带有附件的 MailMessage:

        string file = "data.xls";

        // Create a message and set up the recipients.
        MailMessage message = new MailMessage(
           "[email protected]",
           "[email protected]");

        message.Subject = "The subject.";
        message.Body = "See the attached file";

        // Create  the file attachment for this e-mail message.
        Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
        data.ContentId = Guid.NewGuid().ToString();
        // Add time stamp iformation for the file.
        ContentDisposition disposition = data.ContentDisposition;
        disposition.CreationDate = System.IO.File.GetCreationTime(file);
        disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
        disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
        // Add the file attachment to this e-mail message.
        message.Attachments.Add(data);

要使用 SmtpClient 发送 MailMessage:

        //Send the message.
        SmtpClient client = new SmtpClient(server);
        // Add credentials if the SMTP server requires them.
        client.Credentials = CredentialCache.DefaultNetworkCredentials;
        client.Send(message);

To send email in .NET, use the SmtpClient and MailMessage and Attachment classes.

The MailMessage class represents the content of a mail message. The SmtpClient class transmits email to the SMTP host that you designate for mail delivery. You can create mail attachments using the Attachment class.

Assuming you have a HTML newsletter with a separate stylesheet and images, you would need to create a MailMessage with HTML body content and add the external files as attachments. You will need to set the ContentId property of each attachments, and update the references in the HTML to use this.

A href in the body HTML to an attachment uses the cid: scheme. For an attachment with id "xyzzy", the href is "cid:xyzzy".

To construct an MailMessage with a HTML body:

        string content; // this should contain HTML

        // Create a message and set up the recipients.
        MailMessage message = new MailMessage(
           "[email protected]",
           "[email protected]");

        message.Subject = "The subject.";
        message.Body = content;
        message.IsBodyHtml = true;

To construct an MailMessage with an attachment:

        string file = "data.xls";

        // Create a message and set up the recipients.
        MailMessage message = new MailMessage(
           "[email protected]",
           "[email protected]");

        message.Subject = "The subject.";
        message.Body = "See the attached file";

        // Create  the file attachment for this e-mail message.
        Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
        data.ContentId = Guid.NewGuid().ToString();
        // Add time stamp iformation for the file.
        ContentDisposition disposition = data.ContentDisposition;
        disposition.CreationDate = System.IO.File.GetCreationTime(file);
        disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
        disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
        // Add the file attachment to this e-mail message.
        message.Attachments.Add(data);

To send a MailMessage with SmtpClient:

        //Send the message.
        SmtpClient client = new SmtpClient(server);
        // Add credentials if the SMTP server requires them.
        client.Credentials = CredentialCache.DefaultNetworkCredentials;
        client.Send(message);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文