邮件发送的问题

心意 心意 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

import org.springframework.mail.javamail.MimeMessagePreparator
import java.util.Date;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import org.springframework.mail.javamail.*;

public class OneMimeMessagePreparator implements MimeMessagePreparator{

public void prepare(MimeMessage mm) throws Exception {
mm.setRecipient(Message.RecipientType.TO , new InternetAddress( "*****@126.com" ));
mm.setFrom( new InternetAddress( "*****@126.com" ));
mm.setSubject( "I am nocmear" );
Multipart mp = new MimeMultipart();
MimeBodyPart mbp = new MimeBodyPart();
mbp.setText( "hello Kitty " );
mp.addBodyPart(mbp);
mm.setContent(mp);
mm.setSentDate( new Date());
}
}
public class a{
public static void main(String[] args){JavaMailSenderImpl mail = new JavaMailSenderImpl();
Properties prop = new Properties();
prop.setProperty("mail.smtp.auth", "true");
mail.setHost("smtp.126.com");
mail.setPort(25);
mail.setJavaMailProperties(prop);
mail.setUsername("laihui99@126.com");
mail.setPassword("laihui1237");
mail.send(new OneMimeMessagePreparator() )
}


为什么不用调用prepare 而是new 个OneMimeMessagePreparator的类就可以了?
具体是怎么运行的呢这个程序? 求牛人
...全文

相关推荐

评论 12
收藏 已收藏
分享
返回顶部
心意
Java SE 62,620 成员 307,251 内容