嗨,我想通過下面的代碼幫助從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