嗨,我想通过下面的代码帮助从Outlook 2010发送电子邮件。使用java邮件API从Outlook 2010发送邮件
package javamail;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class JavaMailTest {
public static void main(String[] args) {
String host="host";
final String user="[email protected]";//change accordingly
String to="[email protected]";//change accordingly
//Get the session object
Properties props = new Properties();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth", "false");
Session session=Session.getDefaultInstance(props, null);
session.setDebug(true);
//Compose the message
try {
MimeMessage message = new MimeMessage(session);
message.saveChanges();
message.setFrom(new InternetAddress(user));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Test mail");
message.setText("This is test mail.");
//send the message
Transport.send(message);
System.out.println("message sent successfully...");
}
catch (MessagingException e) {e.printStackTrace();}
}
}
上面的代码工作正常,我可以发送邮件(在我的技术管理员启用中继服务器后)。但问题是我无法在我的Outlook中看到发送的邮件。在分析我发现,Java邮件API直接从SMTP服务器发送邮件。但是我希望邮件从我的outlook profile发送,即我应该能够在我的发送邮件文件夹中看到它。我应该怎么做?什么API或第三方开放源码库可以用来实现这一目标?
有你看过任何VBA/Office脚本? – admdrew
@admdrew什么是VBA/Office脚本?它与视觉基本相关吗?不,我不知道上面的脚本语言..最好我想在java中的一些解决方案。 –
什么是VBA/Office脚本?请继续往下看!你也可以使用标准的.NET来做到这一点;我会建议只做一些额外的研究。 – admdrew