Aspose.Words 是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。此外,API支持所有流行的Word处理文件格式,并允许将Word文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。
Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。
Aspose.words 最新下载(qun:761297826)https://www.evget.com/product/4116/download
在大多数情况下,电子邮件按照特定模板以格式良好的布局发送。但是,各种电子邮件编辑器不提供增强的格式选项。在这种情况下,您可以在 Word 文档中创建消息并将其用作电子邮件正文。在本文中,您将学习如何使用Java将 MS Word 文档作为电子邮件正文发送。
一、下载用于在电子邮件中导入 Word 文档的 Java API
为了在电子邮件正文中导入和发送 Word 文档,我们将利用Aspose.Words for Java和 Aspose.Email for Java API 的功能。前者将用于将 Word 文档保存为MHTML格式,而后者将用于创建和发送电子邮件。您可以从以下部分下载 API 或使用 Maven 配置安装它们。
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>https://repository.aspose.com/repo/</url> </repository>
<dependency> <groupId>com.aspose</groupId> <artifactId>aspose-words</artifactId> <version>21.4</version> <type>pom</type> </dependency> <dependency> <groupId>com.aspose</groupId> <artifactId>aspose-email</artifactId> <version>21.3</version> <classifier>jdk16</classifier> </dependency>
二、使用 Java 在电子邮件正文中发送 Word 文档
以下是在电子邮件正文中导入和发送 Word 文档的步骤。
- 使用com.aspose.words.Document类加载 Word 文档。
- 创建ByteArrayOutputStream类的实例。
- 在ByteArrayOutputStream对象中将 Word 文档另存为 MHTML 。
- 在ByteArrayInputStream对象中加载 MHTML 。
- 创建com.aspose.email.MailMessage类的实例并加载保存在ByteArrayInputStream对象中的 MHTML。
- 设置电子邮件的字段,例如收件人、发件人、主题等。
- 创建com.aspose.email.SmtpClient类的实例
- 设置主机并使用SmtpClient.send(MailMessage)方法发送电子邮件。
以下代码示例显示了如何将 Word 文档作为电子邮件正文发送。
// Load the document Document doc = new Document("Document.doc"); // Save to an output stream in MHTML format. ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); doc.save(outputStream, SaveFormat.MHTML); // Load the MHTML stream back into an input stream to use with Aspose.Email. ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); // Create an Aspose.Email MIME email message from the stream. MailMessage message = MailMessage.load(inputStream); message.setFrom(new MailAddress("your_from@email.com")); message.getTo().add("your_to@email.com"); message.setSubject("Aspose.Words + Aspose.Email MHTML Test Message"); // Save the message in Outlook MSG format. message.save("Message.msg", SaveOptions.getDefaultMsg()); // Send the message using Aspose.Email SmtpClient client = new SmtpClient(); client.setHost("your_smtp.com"); client.send(message);
以上便是使用 C++ 处理 Word 文档中的注释详细步骤 ,要是您还有其他关于产品方面的问题,欢迎咨询我们,或者加入我们官方技术交流群。