发送邮件附件excel_从Excel发送带有PDF附件的电子邮件

发送邮件附件excel

This week, I was experimenting with sending email from Excel via Outlook. The goal was to send an email to each name in a list, and attach a couple of PDF files. Here's how I managed to send email with PDF attachment from Excel.

本周,我正在尝试通过Outlook从Excel发送电子邮件。 目的是向列表中的每个名称发送电子邮件,并附加几个PDF文件。 这是我如何从Excel发送带有PDF附件的电子邮件的方法。

样本文件 (The Sample File)

So, before creating my complex email code, I set up a little test file, with a short list of fake customers. I created this file using Outlook and Excel 2013, but it should also work in Excel 2010, and perhaps Excel 2007 (see Ron de Bruin’s article for 2007 requirements).

因此,在创建复杂的电子邮件代码之前,我设置了一个小

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用JavaMail API来发送带有附件邮件。下面是一个示例代码: ```java import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; public class SendEmailWithAttachment { public static void main(String[] args) { final String username = "your_email_address"; final String password = "your_email_password"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("from_address")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("to_address")); message.setSubject("Testing Subject"); // 创建一个多部分消息 Multipart multipart = new MimeMultipart(); // 创建文本消息部分 MimeBodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText("This is message body"); // 添加文本消息部分到多部分消息 multipart.addBodyPart(messageBodyPart); // 创建附件部分 MimeBodyPart attachPart = new MimeBodyPart(); // 读取附件文件 String filename = "attachment_file_path"; DataSource source = new FileDataSource(filename); attachPart.setDataHandler(new DataHandler(source)); attachPart.setFileName("attachment_file_name"); // 添加附件部分到多部分消息 multipart.addBodyPart(attachPart); // 将多部分消息设置为消息内容 message.setContent(multipart); // 发送消息 Transport.send(message); System.out.println("邮件发送"); } catch (MessagingException e) { throw new RuntimeException(e); } } } ``` 在代码中,你需要替换以下变量: - `your_email_address`:你的邮箱地址 - `your_email_password`:你的邮箱密码 - `from_address`:发件人邮箱地址 - `to_address`:收件人邮箱地址 - `attachment_file_path`:附件文件路径 - `attachment_file_name`:附件文件名 注意:在使用JavaMail API发送邮件时,你需要提供你所使用的邮件服务的SMTP服务器地址和端口号。在上面的代码中,我使用的是Gmail的SMTP服务器,如果你使用的是其他邮件服务,请替换相应的SMTP服务器地址和端口号。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值