java培训_博益教育 java培训就业班_博益教育

                                          当前位置:博益教育 > java热点 >

                                          JavaMail邮件发送-发送带附件的邮件
                                          栏目分类:java热点   发布日期:2025-01-27   浏览次数:652

                                          之前仍然望到,倘使新闻包指定了他们之间的干系,增长1个文献入来,邮箱便会表现成平凡附件

                                          然则那究竟结果没有是附件,附件便是附件没有能暗昧

                                          本来增进附件很复杂

                                          指定新闻包内乱元素为混杂干系

                                          扩张附件并指定附件的称呼

                                          packagecom.mail;importjava.util.Date;importjava.util.Properties;importjavax.activation.DataHandler;importjavax.activation.FileDataSource;importjavax.mail.Message;importjavax.mail.Session;importjavax.mail.Transport;importjavax.mail.internet.InternetAddress;importjavax.mail.internet.MimeBodyPart;importjavax.mail.internet.MimeMessage;importjavax.mail.internet.MimeMultipart;importjavax.mail.internet.MimeUtility;publicclassHtml_File_InnerFile{publicstaticvoidmain(String[]args)throwsException{Propertiesprops=newProperties();props.put("mail.smtp.host","smtp.163.com");props.put("mail.smtp.auth","true");Sessionsession=Session.getInstance(props);Messagemessage=newMimeMessage(session);InternetAddressfrom=newInternetAddress("test20120711120200@163.com");from.setPersonal(MimeUtility.encodeText("风中降叶<test20120711120200@163.com>"));message.setFrom(from);InternetAddressto=newInternetAddress("test20120711120200@163.com");message.setRecipient(Message.RecipientType.TO,to);message.setSubject(MimeUtility.encodeText("强哥恭请,谁敢没有从!"));message.setSentDate(newDate());MimeMultipartmsgMultipart=newMimeMultipart("mixed");//指定为混杂联系message.setContent(msgMultipart);//邮件内乱容MimeBodyParthtmlPart=newMimeBodyPart();htmlPart.setContent("<bodybackground='http://dl.iteye.com/upload/picture/pic/110267/e244bda9-9034-36e3-87fd-807629b84222.jpg'>"+"<divstyle='position:absolute;left:390px;top:150px;height:"+"100px;width:200px;'align='center'>"+"<fontcolor='red'>那是尝试邮件,请勿归复</font>"+"</div></body>","text/html;charset=UTF-8");//TODO拼装的规律十分紧张,必定要先组建文原域,再组建文献msgMultipart.addBodyPart(htmlPart);//拼装附件MimeBodyPartfile=newMimeBodyPart();FileDataSourcefile_datasource=newFileDataSource("D:\\img201008031058340.zip");DataHandlerdh=newDataHandler(file_datasource);file.setDataHandler(dh);//附件差别内乱嵌内乱容的1个特质是有文献实,为预防华文治码要编码file.setFileName(MimeUtility.encodeText(dh.getName()));msgMultipart.addBodyPart(file);message.saveChanges();Transporttransport=session.getTransport("smtp");transport.connect("smtp.163.com",25,"test20120711120200","test123456");transport.sendMessage(message,message.getAllRecipients());transport.close();System.out.println("收收杀青");}}

                                          重要组建元素的时分必定要先拼装邮件内乱容再组建附件

                                          不管正在 客户端对象依然邮箱,皆是提醒附件,邮件照旧带配景图片的

                                          89fb2b49-ba51-3ef0-949b-8a6d64ab916b.jpg

                                          附件称呼是您本身指定的

                                          推举您浏览更多相关于“ JavaMail邮件平凡附件附件 ”的著作

                                          
                                          Copyright © 2024-2026  java培训_博益教育 java培训就业班_博益教育   http://www.taigangzhonglian.com  .All Rights Reserved   网站地图  无
                                          博益教育 java项目 java热点 联系我们