无法使用Groovy发送带附件的电子邮件

时间:2016-09-07 14:23:26

标签: groovy

我不知道为什么,但我无法导入课程MultiPartEmail。似乎除非导入MultiPartEmail类,否则此代码将无效。

  // Importing Groovy classes
  import org.apache.commons.mail.*;   

  // Create the attachment
  EmailAttachment attachment = new EmailAttachment();
  attachment.setPath("Libraries/Pictures");
  attachment.setDisposition(EmailAttachment.ATTACHMENT);
  attachment.setDescription("company logo.jpg");
  attachment.setName("MyCompany");

  // Create the email message
  MultiPartEmail email = new MultiPartEmail();
  email.setHostName("255.255.255.0");
  email.setPort("25")
  email.addTo("addemailhere", "name");
  email.setFrom("from@anywhere.net", "Sam");
  email.setSubject("Email from Groovy");
  email.setMsg("Test email");

  // add the attachment
  email.attach("company logo.jpg");

  // send the email
  email.send();

0 个答案:

没有答案