我不知道为什么,但我无法导入课程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();