【问题标题】:How to send email using microsoft publisher in body using c#如何使用 C# 在正文中使用 Microsoft Publisher 发送电子邮件
【发布时间】:2011-01-20 00:22:44
【问题描述】:

您好,我有一个新要求。如何在邮件的正文内容中发送时事通讯。

时事通讯由 Microsoft Publisher 应用程序制作。

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

谢谢

【问题讨论】:

  • 您目前如何发送邮件?
  • 这是一个新要求。我没有使用 microsoft Publisher 发送邮件的经验。所以我在 net/google 中搜索这个

标签: c# .net email ms-publisher


【解决方案1】:

Lachlan Roche 有一个很好的答案。 我只想补充一点,您可能会考虑输出时事通讯 到 Adob​​e Acrobat、图像文件或 html。

新闻通讯所针对的大多数人可能没有安装 Publisher。 所以向他们发送 .pub 文件可能不会达到预期的效果。

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

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

【讨论】:

    【解决方案2】:

    要在 .NET 中发送电子邮件,请使用 SmtpClientMailMessageAttachment 类。

    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(
               "from@example.com",
               "to@example.com");
    
            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(
               "from@example.com",
               "to@example.com");
    
            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);
    

    【讨论】:

      猜你喜欢
      • 2014-07-19
      • 2011-02-18
      • 2012-05-17
      • 2016-04-17
      • 1970-01-01
      • 1970-01-01
      • 2012-02-25
      • 2010-10-01
      相关资源
      最近更新 更多