0

我是斯卡拉的新手。我在我的项目中使用 apache-james-3.0,Scala。我想将通知消息作为 no-reply@myservicename.com 发送到外部电子邮件。James 有一个邮政主管 (http://james.apache.org/server/3/config-mailetcontainer.html)。我的问题是我不知道如何进一步从 mailetcontainer.conf 文件中读取 postmaster 用户,我需要将字段设置为 from(message.setFrom)。

我的代码:

val properties = new Properties();
val host = "mylocalserver.com";         
properties.put("mail.smtp.host", host);
properties.setProperty("mail.transport.protocol", "smtp"); 
properties.put("mail.smtp.auth", "true"); 
properties.setProperty("mail.user", "login@login.com"); 
properties.setProperty("mail.password", "psw"); 
val emailSession = Session.getDefaultInstance(properties);
val emailMessage = new MimeMessage(emailSession);
emailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress("login1@login1.com"));
emailMessage.addRecipient(Message.RecipientType.CC, new InternetAddress("login2@login2.com"));
emailMessage.setFrom(new InternetAddress("postmaster@mylocalserver.com"));
emailMessage.setSubject("subject sd sd sdsd");
emailMessage.setText("body vodiy text text");
emailSession.setDebug(true);
Transport.send(emailMessage)

我如何达到它?请帮帮我,解释一下!提前致谢!

4

0 回答 0