精华内容
下载资源
问答
  • 只用于发送邮件,设置账号时要注意用户名和邮箱的区别package com.landray.kmss.pro.leadroute.service.spring;import java.util.Properties;import javax.mail.Authenticator;import javax.mail.Message;import ...

    只用于发送邮件,设置账号时要注意用户名和邮箱的区别

    package com.landray.kmss.pro.leadroute.service.spring;

    import java.util.Properties;

    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 ToExchangeMail {

    public static String sendMain(String to) {

    String from = "xxx@qq.com";// 发件人电子邮箱

    //获取系统属性,主要用于设置邮件相关的参数。

    Properties properties = System.getProperties();

    properties.setProperty("mail.smtp.host", "smtp.xxx");//smtp协议地址

    properties.setProperty("mail.smtp.port", "xx");//端口号

    Session session = Session.getDefaultInstance(properties, new Authenticator() {

    @Override

    protected PasswordAuthentication getPasswordAuthentication() {

    return new PasswordAuthentication("发送者邮箱的用户名(不是邮箱)", "密码");//发送者账号密码

    }

    });

    //创建MimeMessage消息对象,消息头配置了收发邮箱的地址,消息体包含了邮件标题和邮件内容。接收者类型:TO代表直接发送,CC代表抄送,BCC代表秘密抄送。

    try {

    MimeMessage message = new MimeMessage(session);

    message.addHeader("X-Mailer","Microsoft Outlook Express 6.00.2900.2869");

    message.setFrom(new InternetAddress(from));

    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

    message.setSubject("标题");

    message.setText("内容");

    Transport.send(message);

    System.out.println("发送成功!");

    return "success";

    } catch (MessagingException e) {

    e.printStackTrace();

    return "failed";

    }

    }

    }

    测试类:

    public class MyTest {

    public static void main(String[] args) {

    ToExchangeMail mail=new ToExchangeMail();

    mail.sendMain("接收人的邮箱");

    }

    }

    展开全文
  • 上一篇是java发送邮件,小白再次编写了java发送outlook会议邮件,保证可执行!
  • java使用outlook发邮件

    2021-09-26 15:37:34
    /* ... *return:String */ public static String sendMain(String username, String password, String to) ... //设置邮件传输服务器,由于本次是发送邮件操作,所需我们需要配置smtp协议,按outlook官方同步邮件的要.
    	/*
    	*param: 邮箱,密码,收件人邮箱
    	*return:String
    	*/
    	public static String sendMain(String username, String password, String to) {
    		//获取系统属性,主要用于设置邮件相关的参数。
    		Properties properties = System.getProperties();
    		//设置邮件传输服务器,由于本次是发送邮件操作,所需我们需要配置smtp协议,按outlook官方同步邮件的要求,依次配置协议地址,端口号和加密方法
    		properties.setProperty("mail.smtp.host", "smtp.office365.com");
    		properties.setProperty("mail.smtp.port", "587");
    		properties.setProperty("mail.smtp.starttls.enable", "true");
    		//用户验证并返回Session,开启用户验证,设置发送邮箱的账号密码。
    		properties.setProperty("mail.smtp.auth", "true");
    		Session session = Session.getDefaultInstance(properties, new Authenticator() {
    		    @Override
    		    protected PasswordAuthentication getPasswordAuthentication() {
    		        return new PasswordAuthentication(username, password);//账号密码
    		    }
    		});
    		
    		//创建MimeMessage消息对象,消息头配置了收发邮箱的地址,消息体包含了邮件标题和邮件内容。接收者类型:TO代表直接发送,CC代表抄送,BCC代表秘密抄送。
    		try {
    		    MimeMessage message = new MimeMessage(session);
    		    message.addHeader("X-Mailer","Microsoft Outlook Express 6.00.2900.2869");
    		    message.setFrom(new InternetAddress(username));
    		    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    		    message.setSubject("测试");
    		    message.setText("这是使用Java发送邮件的测试!");
    //		    Transport.send(message);
    //		    System.out.println("发送成功!");
    			
    			// 1.创建复合消息体
    			Multipart multipart = new MimeMultipart();
    			// 2.添加附件, 报错
    			BodyPart filePart = new MimeBodyPart();
    			String filePath = "*.*"; //文件  
    			DataSource source = new FileDataSource(filePath);
    			filePart.setDataHandler(new DataHandler(source));
    			filePart.setFileName(source.getName());
    			multipart.addBodyPart(filePart);
    			// 3.添加文本内容
    			MimeBodyPart textPart = new MimeBodyPart();
    			textPart.setText("测试包含文本和附件的邮件!");
    			multipart.addBodyPart(textPart);
    			// 4.绑定消息对象
    			message.setContent(multipart);
    			// 5.发送邮件
    			Transport.send(message);
    		    return "邮件发送成功";
    		} catch (MessagingException e) {
    		    e.printStackTrace();
    		    return "邮件发送失败!";
    		}
    		
    	}
    
    展开全文
  • java outlook发送邮件

    2021-02-12 18:54:58
    java outlook发送邮件package test.first.javamail;import java.util.Properties;import javax.activation.DataHandler;import javax.activation.DataSource;import javax.activation.FileData...

    我试图通过outlook发送邮件,但收到错误如下。java outlook发送邮件

    package test.first.javamail;

    import java.util.Properties;

    import javax.activation.DataHandler;

    import javax.activation.DataSource;

    import javax.activation.FileDataSource;

    import javax.mail.BodyPart;

    import javax.mail.Message;

    import javax.mail.MessagingException;

    import javax.mail.Multipart;

    import javax.mail.PasswordAuthentication;

    import javax.mail.Session;

    import javax.mail.Transport;

    import javax.mail.internet.InternetAddress;

    import javax.mail.internet.MimeBodyPart;

    import javax.mail.internet.MimeMessage;

    import javax.mail.internet.MimeMultipart;

    public class SendAttachmentInEmail {

    public static void main(String[] args) {

    // Recipient's email ID needs to be mentioned.

    // String to = "[email protected]";

    // Sender's email ID needs to be mentioned

    String from = "[email protected]";

    final String password = "*****";// change accordingly

    // Check how many arguments were passed in

    if (args.length == 0) {

    System.out.println("Please run Sendmail jar as: java -jar SendMail.jar ");

    System.exit(0);

    }

    String to = args[0];

    String attachment_path = args[1];

    final String username = from;

    ;// change accordingly

    System.out.println("Trying to send mail to : " + to + "\n");

    // final String username = "abcd";// change accordingly

    // final String password = "******";// change accordingly

    System.out.println("Please wait for a moment, we are checking creadentials...! \n");

    Properties props = new Properties();

    props.put("mail.smtp.auth", "true");

    props.put("mail.smtp.starttls.enable", "true");

    // props.put("mail.smtp.host", "smtp.gmail.com");smtp.office365.com

    props.put("mail.smtp.host", "smtp.office365.com");

    props.put("mail.smtp.port", "587");

    // props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

    // props.put("mail.smtp.socketFactory.fallback", "true");

    // Get the Session object.

    Session session = Session.getInstance(props,

    new javax.mail.Authenticator() {

    protected PasswordAuthentication getPasswordAuthentication() {

    return new PasswordAuthentication(username, password);

    }

    });

    System.out.println("Seat tight your identity has been proved and mail is just on the way...! ");

    try {

    // Create a default MimeMessage object.

    Message message = new MimeMessage(session);

    // Set From: header field of the header.

    message.setFrom(new InternetAddress(from));

    // Set To: header field of the header.

    message.setRecipients(Message.RecipientType.TO,

    InternetAddress.parse(to));

    // Set Subject: header field

    message.setSubject("Testing Subject");

    // Create the message part

    BodyPart messageBodyPart = new MimeBodyPart();

    // Now set the actual message

    messageBodyPart.setText("This is message body");

    // Create a multipar message

    Multipart multipart = new MimeMultipart();

    // Set text message part

    multipart.addBodyPart(messageBodyPart);

    // Part two is attachment

    messageBodyPart = new MimeBodyPart();

    String filename = attachment_path;// "C:/Users/swapnil.kotwal/Desktop/buildsuccess.txt";Azure.png

    DataSource source = new FileDataSource(filename);

    messageBodyPart.setDataHandler(new DataHandler(source));

    messageBodyPart.setFileName(filename);

    multipart.addBodyPart(messageBodyPart);

    // Send the complete message parts

    message.setContent(multipart);

    // Send message

    Transport.send(message);

    System.out.println("Sent message successfully....");

    } catch (MessagingException e) {

    throw new RuntimeException(e);

    }

    }

    }

    错误是

    Exception in thread "main" java.lang.RuntimeException: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.office365.com, 587; timeout -1;

    nested exception is:

    java.net.ConnectException: Connection timed out: connect

    at test.first.javamail.SendAttachmentInEmail.main(SendAttachmentInEmail.java:104)

    Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.office365.com, 587; timeout -1;

    nested exception is:

    java.net.ConnectException: Connection timed out: connect

    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2100)

    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:699)

    at javax.mail.Service.connect(Service.java:367)

    at javax.mail.Service.connect(Service.java:226)

    at javax.mail.Service.connect(Service.java:175)

    at javax.mail.Transport.send0(Transport.java:253)

    at javax.mail.Transport.send(Transport.java:124)

    at test.first.javamail.SendAttachmentInEmail.main(SendAttachmentInEmail.java:99)

    Caused by: java.net.ConnectException: Connection timed out: connect

    at java.net.DualStackPlainSocketImpl.connect0(Native Method)

    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

    at java.net.PlainSocketImpl.connect(Unknown Source)

    at java.net.SocksSocketImpl.connect(Unknown Source)

    at java.net.Socket.connect(Unknown Source)

    at java.net.Socket.connect(Unknown Source)

    at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:331)

    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:238)

    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2066)

    我相信代码是正确的,但不能确定究竟是什么阻止了邮件传递?任何帮助将不胜感激。

    +0

    检查SMTP服务器和端口是否正确。 –

    展开全文
  • I am stuck behind a corporate firewall that won't let me send email via conventional means such as Java Mail API or Apache Commons Email, even to other people inside the organization(which is all I wa...

    I am stuck behind a corporate firewall that won't let me send email via conventional means such as Java Mail API or Apache Commons Email, even to other people inside the organization(which is all I want anyways). But my Outlook 2010 obviously can send these emails. I was wondering if there is a way to automate Outlook 2010 via Java code so that Outlook can send the emails ? I know stuff like "mailto" can be used pop-up the default Outlook send dialog with pre-populated info, but I am looking for a way to have the send operation happen behind the scenes. Thanks for any info.

    解决方案

    You can send emails through outlook with javamail use the configurations described on Outlook's official site.

    Here is small demo code

    public static void main(String[] args) {

    final String username = "your email"; // like yourname@outlook.com

    final String password = "*********"; // password here

    Properties props = new Properties();

    props.put("mail.smtp.auth", "true");

    props.put("mail.smtp.starttls.enable", "true");

    props.put("mail.smtp.host", "smtp-mail.outlook.com");

    props.put("mail.smtp.port", "587");

    Session session = Session.getInstance(props,

    new javax.mail.Authenticator() {

    @Override

    protected PasswordAuthentication getPasswordAuthentication() {

    return new PasswordAuthentication(username, password);

    }

    });

    session.setDebug(true);

    try {

    Message message = new MimeMessage(session);

    message.setFrom(new InternetAddress(username));

    message.setRecipients(Message.RecipientType.TO,

    InternetAddress.parse("receiver mail")); // like inzi769@gmail.com

    message.setSubject("Test");

    message.setText("HI you have done sending mail with outlook");

    Transport.send(message);

    System.out.println("Done");

    } catch (MessagingException e) {

    throw new RuntimeException(e);

    }

    }

    .

    Note: I tested this with Javamail API 1.5.6

    展开全文
  • 准备我们想通过Java代码实现发送OutLook邮件,必须准备以下材料:OutLook邮箱目标邮箱查看OutLook邮箱信息打开OutLook邮箱,在Settings中搜索或找到SMTP:打开以下界面,拿到我们想要的数据(ServerName 以及 Port),...
  • java实现模板邮件发送

    2019-03-17 18:08:31
    本资源适合正在学习邮件的学员,要有一定java基础的学员学习。
  • 主要包括:SMTP协议:Simple Mail Transfer Protocol,即简单邮件传输协议,用于发送电子邮件POP3协议:Post Office Protocol 3,即邮局协议的第三个版本,用于接收邮件IMAP协议:Internet Message Access Protocol...
  • java发送outlook邮件

    千次阅读 2018-11-28 17:02:50
    记录下发送outlook邮件 Exchange Web服务(EWS)Java API提供了一个托管接口, 中文文档地址为 ... 首...
  • 再次在产品规模上,大公司产品的日活规模可能少则上百万,多则上亿,不论是在技术实现还是产品运营上,都需要较高的要求与水准,你在其中能学习的技能与套路是小公司日活几千或几万的产品规模无法比拟的。...
  • Java查询OutLook邮件代码,仅供参考
  • java mail调用outlook的方法例子1 将邮件写入到文件的代码msg.saveChanges();File f = new File("d:/test.eml");msg.writeTo(new FileOutputStream(f));2 调用outlook的代码Process p = Runtime.getRuntime().exec(...
  • 和JavaScript会要求的电子邮件地址,主题,等等然后你,新的邮件,是向你打开了。 [removed] <!-- Begin function mailsome1(){ who=prompt("Enter recipient's email address: ","antispammer@earthling...
  • 首先引入maven依赖 <dependency> <groupId>com.microsoft.ews-java-api<...ews-java-api</artifactId> <version>2.0</version> </dependency> packag
  • 展开全部java mail调用outlook的方法例子1 将邮件写入到文件的代码msg.saveChanges();File f = new File("d:/test.eml");msg.writeTo(new FileOutputStream(f));2 调用outlook的代码Process p = Runtime.getRuntime...
  • outlook客户端显示的图片都会自动更改图片大小 也无法使图片横向显示的 就导致图片很大,而且一行一个 解决方案 outlook显示html时 都会转码成自家的vml格式 只要在代码中忽略此格式即可 <![if !vml]>...
  • //MailPOJO.java /* * * */ package com.httech.hrms.bean; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Data; ...
  • Java发送outlook邮件

    热门讨论 2011-07-25 09:16:09
    Java发送outlook邮件,也可发送notes邮件
  • 再次在产品规模上,大公司产品的日活规模可能少则上百万,多则上亿,不论是在技术实现还是产品运营上,都需要较高的要求与水准,你在其中能学习的技能与套路是小公司日活几千或几万的产品规模无法比拟的。...
  • 封装好了方法, 传入发送邮件的邮箱和收邮件的邮箱即可测试使用
  • 我正在尝试使用JavaMail以html格式发送电子邮件,但它似乎始终只在Outlook中显示为文本电子邮件。这是我的代码:try{Properties props = System.getProperties();props.put("mail.smtp.host", mailserver);props.put...
  • 请问如何用java调用Outlook Express,并发送邮件
  • /*** 带附件*@parammail 邮箱对象*@paramto 收件人*@paramFile_Path 附件存放路径*@return*/public static booleansendMain(MailPOJO mail,String to,String File_Path) {//获取系统属性,主要用于设置邮件相关的...
  • 发送邮件要提前准备好要发送的数据类容,还要提前将件箱协议名,身份验证信息,服务主机名准备好以outlook邮箱为例,如图所示: 在SMTP中可以看见相关设置。 接下来直接上代码: //这个Map存放Html模板中的类...
  • 方法1:让发邮件的人通过outlook导出html或者eml等通用的格式给你 方法2:利用在线转换为eml,点击这里这种比较方便,推荐 方法3:使用转换软件转换为eml等格式,比如SysTools MSG to EML Converter 方法4:利用java...
  • springboot如何使用outlook发送邮件

    万次阅读 2020-10-30 23:50:10
    进入后选择邮件->同步电子邮件 打开pop如上设置 下面是我的application.propertis设置 请填上自己的邮箱名与密码,outlook邮箱目前不需要授权码,密码就是自己的邮箱密码 记得按下面开启tls验证,不然会...
  • 发送邮件失败提示如下: javax.mail.AuthenticationFailedException: 421 4.7.66 TLS 1.0 and 1.1 are not supported. Please upgrade/update your client to support TLS 1.2. Visit ...
  • outlook带会议提醒javaDemo 可运行

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 4,612
精华内容 1,844
关键字:

java实现outlook发送邮件

java 订阅