是否可以使用Java Mail連接到Exchange Online Server(Office 365)?可以使用JavaMail連接Exchange Online Server(Office 365)嗎?
0
A
回答
0
是的,這是我從github
import java.util.Date;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Authenticator;
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 SendEmailOffice365 {
private static final Logger LOGGER = Logger.getAnonymousLogger();
private static final String SERVIDOR_SMTP = "smtp.office365.com";
private static final int PORTA_SERVIDOR_SMTP = 587;
private static final String CONTA_PADRAO = "[email protected]";
private static final String SENHA_CONTA_PADRAO = "password*";
private final String from = "[email protected]";
private final String to = "[email protected]";
private final String subject = "Teste";
private final String messageContent = "Teste de Mensagem";
public void sendEmail() {
final Session session = Session.getInstance(this.getEmailProperties(), new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(CONTA_PADRAO, SENHA_CONTA_PADRAO);
}
});
try {
final Message message = new MimeMessage(session);
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setFrom(new InternetAddress(from));
message.setSubject(subject);
message.setText(messageContent);
message.setSentDate(new Date());
Transport.send(message);
} catch (final MessagingException ex) {
LOGGER.log(Level.WARNING, "Erro ao enviar mensagem: " + ex.getMessage(), ex);
}
}
public Properties getEmailProperties() {
final Properties config = new Properties();
config.put("mail.smtp.auth", "true");
config.put("mail.smtp.starttls.enable", "true");
config.put("mail.smtp.host", SERVIDOR_SMTP);
config.put("mail.smtp.port", PORTA_SERVIDOR_SMTP);
return config;
}
public static void main(final String[] args) {
new SendEmailOffice365().sendEmail();
}
}
+0
謝謝Yohannes。我認爲,如果您可以連接發送郵件,也可以連接到閱讀收件箱/文件夾。 –
+0
理想情況是的。很難僅支持發送部分。 –
0
微軟有太多的產品與真內相同名稱不同了一個例子!這些JavaMail FAQ instructions應該有所幫助,但是您必須更改主機名。
相關問題
- 1. Office 365:使用Power Shell腳本連接到Office Online 365服務
- 2. StreamingNotifications不適用於Office 365/Exchange Online
- 3. 經驗上EWSMA和Exchange Online Office 365的
- 4. 將Silverlight連接到Office 365 /「Sharepoint 2010 online」
- 5. 通過Exchange Online(Office 365)使用System.Net.Mail發送SMTP電子郵件
- 6. 使用OAuth的Office 365 Exchange ActiveSync
- 7. 如何使用PHPMailer連接到Office 365?
- 8. 我們可以使用EWS託管API連接到Exchange 2016嗎?
- 9. 在Exchange Online上使用New-MailboxSearch
- 10. Office 365 Outlook API(Exchange管理中心)
- 11. 我可以在Office 365上調試工作流程嗎?
- 12. 如何在線使用Microsoft Office 365 OUTLOOK與Microsoft Dynamics CRM Online
- 13. 使用jQuery或JavaScript從Office 365(Sharepoint Online)獲取listitem?
- 14. WOPI使用office 365
- 15. 我們可以每天進行30,000次Office 365 API調用嗎?
- 16. 帶有SQL Azure和實體框架的Office 365中的SharePoint Online
- 17. 連接到Exchange asyncronously使用PowerShell
- 18. 如何從Exchange Online取數據而不使用Azure AD
- 19. 使用PHP和LDAP連接到Microsoft Office 365
- 20. 無法使用php連接到Office 365 imap_open
- 21. Office 365 GetByteArrayAsync
- 22. 通過適用於Office 365的ADFS進行SSO(SharePoint Online)
- 23. 如何使用Office 365的
- 24. 在Office 365中使用ExcelServices?
- 25. Office 365禁止403
- 26. 鏈接到Office 365帳戶
- 27. Xamarin.Android Office 365身份驗證
- 28. Office 365/Sharepoint API
- 29. 連接到Exchange Online的C#控制檯應用程序
- 30. 與Office 365
我從來沒有嘗試過,但通過這個頁面它似乎支持所有需要的協議:https://support.microsoft.com/en-us/help/2021880/configuring-outlook-for-microsoft-online -services-mso –
@ ismsankalp89編輯被拒絕。我們不是盲目的。 – EJP
謝謝你的信息。 –