一、下载用于在电子邮件中导入 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 documentDocument 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.EmailSmtpClient client = new SmtpClient();client.setHost("your_smtp.com");client.send(message);
以上便是使用 C++ 处理 Word 文档中的注释详细步骤,要是您还有其他关于产品方面的问题,欢迎咨询我们,或者加入我们官方技术交流群。
欢迎下载|体验更多Aspose产品
点此获取更多Aspose产品信息 或 加入Aspose技术交流群()
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!