是否可以使用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
谢谢你的信息。 –