1

您好,我有一个新要求。如何在邮件正文中发送简报。

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

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

谢谢

4

2 回答 2

4

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

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

我假设您的客户希望能够在 Publisher 中调用宏或 Office 应用程序,以将他们编写的时事通讯作为电子邮件发送到人员列表。

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

于 2010-02-26T04:34:51.797 回答
1

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

        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(
           "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);

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);
于 2010-02-26T04:13:06.323 回答