Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Yahoo&;Gmail_Java_Email_Content Type_Email Attachments_Email Headers - Fatal编程技术网

Java Yahoo&;Gmail

Java Yahoo&;Gmail,java,email,content-type,email-attachments,email-headers,Java,Email,Content Type,Email Attachments,Email Headers,我有一个问题,java中的一段代码可以发送电子邮件,除了像Yahoo&Gmail这样的公开电子邮件 以下是我发送到公司电子邮件地址时收到的电子邮件的标题: Date: Wed, 30 Apr 2014 10:56:05 -0400 From: <test@mycompany.com> To: <testmycompany@gmail.com> Message-ID: <743410318.7.1398869765575.JavaMail.test@test-win7

我有一个问题,java中的一段代码可以发送电子邮件,除了像Yahoo&Gmail这样的公开电子邮件

以下是我发送到公司电子邮件地址时收到的电子邮件的标题:

Date: Wed, 30 Apr 2014 10:56:05 -0400
From: <test@mycompany.com>
To: <testmycompany@gmail.com>
Message-ID: <743410318.7.1398869765575.JavaMail.test@test-win7>
Subject: Order Attached
MIME-Version: 1.0
Content-Type: multipart/mixed;
    boundary="----=_Part_6_255846116.1398869765268"
Return-Path: test@mycompany.com
X-MS-Exchange-Organization-AuthSource: S1P5HUB7.EXCHPROD.USA.NET
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Organization-AVStamp-Mailbox: SMEXtG}w;1076300;0;This mail has
 been scanned by Trend Micro ScanMail for Microsoft Exchange;
X-MS-Exchange-Organization-SCL: 0
X-EsetId: B021473D1D017139E26C16

邮件头上是否有遗漏的内容?您应该检查邮件服务器的响应。我曾经尝试连接到gmail服务器以检查是否存在邮件地址,但没有成功,因为我的ISP的ip块被列入黑名单,以避免来自受感染家庭计算机的垃圾邮件。我忘了链接,但有一个网站,你可以检查你的ip是否被列入黑名单

MimeMessage msg = new MimeMessage(mailSession);
      msg.setHeader("Content-Type", getContentType(email.getContentType()));
      msg.setFrom(getInternetAddress((email.getFrom() == null || email.getFrom().getEmail() == null) ? new EmailAddress(emailConfiguration.getDefaultFromEmail()) : email.getFrom()));
      msg.setRecipients(Message.RecipientType.TO, getRecipientArray(email.getRecipients()));
      msg.setSubject(email.getSubject(), getContentType(email.getContentType()));
      msg.setSentDate(new Date());
  if (email.getAttachments() == null || email.getAttachments().size() == 0) {
    msg.setContent(new String(email.getBody()), getContentType(email.getContentType()));
  } else {
    MimeMultipart body = new MimeMultipart();
    email.setBody("This is a new Vendor Order.\nPlease respond.");
    if (email.getBody() != null && email.getBody().length > 0) {
      MimeBodyPart textPart = new MimeBodyPart();
      textPart.setContent(new String(email.getBody()), getContentType(email.getContentType()));
      body.addBodyPart(textPart);
    }
    for (EmailAttachment attachment: email.getAttachments()) {
      MimeBodyPart part = new MimeBodyPart();
      InMemoryDataSource fds = new InMemoryDataSource(attachment);
      part.setDataHandler(new DataHandler(fds));
      part.setFileName(fds.getName());
      body.addBodyPart(part);
    }
    msg.setContent(body);
  }

  transport = mailSession.getTransport(msg.getFrom()[0]);
  Socket socket = new Socket(emailConfiguration.getMailHost(), emailConfiguration.getMailPort());
  socket.setSoTimeout(emailConfiguration.getIdleTimeoutInSeconds() * 1000);
  if (connectionListener != null) {
    connectionListener.setSocket(socket);
  }
  ((SMTPTransport)transport).connect(socket);
  transport.sendMessage(msg, msg.getRecipients(Message.RecipientType.TO));