这是代码的一部分。当我不使用此代码消息发送时。
messageBodyPart=new MimeBodyPart();
DataSource fds=new FileDataSource("btn2.png");
messageBodyPart.setDataHandler(new DataHandler(fds));
messageBodyPart.setHeader("Content-ID","<image>");
messageBodyPart.addHeader("Content-Type","image/png");
messageBodyPart.setDisposition(MimeBodyPart.INLINE);
multipart.addBodyPart(messageBodyPart);
但是当我添加此代码消息而不是发送时。 这是完整的代码。
Properties props=System.getProperties();
String fromm="ffff@ffff.fffff.fff";
String pass="ffffffffff";
String to="afffffffffff@gmail.com";
props.put("mail.smtp.starttls.enable",true);
props.put("mail.smtp.host","ggg.ggg.ggg.gggg");
props.put("mail.smtp.user",fromm);
props.put("mail.smtp.password",pass);
props.put("mail.smtp.port","587");
props.put("mail.smtp.auth",true);
Session session=Session.getInstance(props,null);
MimeMessage message=new MimeMessage(session);
InternetAddress from=new InternetAddress(fromm);
message.setSubject("Salam mailiniz var");
message.setFrom(from);
message.addRecipients(Message.RecipientType.TO,InternetAddress.parse(to));
Multipart multipart=new MimeMultipart();
BodyPart messageBodyPart=new MimeBodyPart();
String htmlText="<H1>Hello from the outside Hello, can you hear me?</H1><img src=\"cid:image\">";
messageBodyPart.setContent(htmlText,"text/html; charset=utf-8");
multipart.addBodyPart(messageBodyPart);
messageBodyPart=new MimeBodyPart();
DataSource fds=new FileDataSource("btn2.png");
messageBodyPart.setDataHandler(new DataHandler(fds));
messageBodyPart.setHeader("Content-ID","<image>");
messageBodyPart.addHeader("Content-Type","image/png");
messageBodyPart.setDisposition(MimeBodyPart.INLINE);
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
Transport transport=session.getTransport("smtp");
transport.connect("mail.mct.gov.az",fromm,pass);
transport.sendMessage(message,message.getAllRecipients());