本文实例为大家分享了Java通过exchange协议发送邮件的具体代码,供大家参考,具体内容如下
pom.xml 导入包
<dependency>
<groupId>com.microsoft.ews-java-api</groupId>
<artifactId>ews-java-api</artifactId>
<version>2.0</version>
</dependency>
application.properties 配置信息
#邮箱地址
youjia.exchange.mail.username=123@abc.com
#邮箱密码
youjia.exchange.mail.password=123456
#邮箱exchange服务地址,如果不知道找运维
youjia.exchange.mail.host=https://*****/ews/exchange.asmx
package com.youjia.found.manager;
import com.youjia.found.common.util.Check;
import microsoft.exchange.webservices.data.core.ExchangeService;
import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
import microsoft.exchange.webservices.data.core.enumeration.property.BodyType;
import microsoft.exchange.webservices.data.core.service.item.EmailMessage;
import microsoft.exchange.webservices.data.credential.ExchangeCredentials;
import microsoft.exchange.webservices.data.credential.WebCredentials;
import microsoft.exchange.webservices.data.property.complex.MessageBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.mail.internet.InternetAddress;
import java.net.URI;
/**
* <P>exchange邮件处理类</P>
*
* @author eric
* @date 2020/2/6 11:08 AM
* @since
*/
@Component
public class MailExchangeManager {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Value("${youjia.exchange.mail.username}")
private String username ;
@Value("${youjia.exchange.mail.password}")
private String password;
@Value("${youjia.exchange.mail.host}")
private String host ;
/**
* 使用Exchange协议发送
* @param to 收件人
* @param subject 邮件主题
* @param content 正文
* @param filePath 附件
*
* @throws Exception
*/
public boolean sendMail(String to, String subject, String content, String filePath) {
logger.info("exchange邮件发送 to:{}, subject:{}, content:{},filePath:{}", to, subject, content,filePath);
boolean isOK=false;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
ExchangeCredentials credentials = new WebCredentials(username,password);
service.setCredentials(credentials);
try {
service.setUrl(new URI(host));
EmailMessage msg = new EmailMessage(service);
msg.setSubject(subject);
MessageBody body = MessageBody.getMessageBodyFromText(content);
body.setBodyType(BodyType.HTML);
msg.setBody(body);
//支持多个收件人
InternetAddress[] addresses = InternetAddress.parse(to);
for (InternetAddress address : addresses) {
msg.getToRecipients().add(address.getAddress());
}
if (Check.notEmpty(filePath)) {
msg.getAttachments().addFileAttachment(filePath);
}
msg.send();
isOK=true;
} catch (Exception e) {
logger.error(e.getMessage(),e);
isOK= false;
}
return isOK;
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持小牛知识库。
我在使用我的公司交换服务器通过Javamail发送电子邮件时遇到了一些问题。我们有一个应用程序通过gmail服务器发送电子邮件没有任何问题,但对于Google策略的一些更改,我们希望使用公司服务器来完成这项工作。我确信会话属性中的问题,但我无法找到使其工作的方法 这是显示日志的错误 javax.mail.MessagingException:无法连接到SMTP主机:mail.company.com
本文向大家介绍python基于SMTP协议发送邮件,包括了python基于SMTP协议发送邮件的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了python基于SMTP协议发送邮件的具体代码,供大家参考,具体内容如下 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持呐喊教程。
我想用Java从我的公司Outlook帐户发送邮件。但它说邮箱无法访问。我试过各种解决方案,比如更改主机名,但还是不行。错误保持不变。请对此提出任何解决方案。下面是我面临的错误片段。注意:我使用javax mail来实现这个目的。
MainClass: 例外情况:
嗨,我目前正在开发java应用程序,该应用程序将通过java mail Api(1.6.2)向多个收件人发送邮件,我已经根据Microsoft文档配置了SMTP。问题是代码正在使用我的个人hotmail电子邮件id,但对于公司office 365帐户,它失败了。 错误:javax.mail.身份验证失败异常:535 5.7.3身份验证不成功[PN1PR0101CA0066.INDPRD01.PRO
我有一个由Python构建的API服务器。我需要一组客户端/计算机通过发出http post请求将数据发送到API服务器。 这里的数据实际上是html内容。(注意:我没有将合法数据转换为HTML/XML格式,数据本身就是我从web上收集的HTML),通常每页约200KB。我正试图通过使用串行/串行和压缩来尽可能减轻网络负载。 我正在考虑通过网络发送原始超文本标记语言。有没有类似序列化html对象的