发邮件出现IOException和MessagingException如何解决,求大神们帮忙! - 爱问答

(爱问答)

发邮件出现IOException和MessagingException如何解决,求大神们帮忙!

方法代码如下,跑出如图的异常 

public void sendmail(Collection file)    throws MailException  {    if (!notifyFlag) {      return;    }

    this.props = System.getProperties();    this.props.put("mail.smtp.host", getHost());    this.props.put("mail.smtp.auth", "false");    this.props.put("mail.transport.protocol", "smtp");    if (this.bolSendPartial) {      this.props.put("mail.smtp.sendpartial", "true");    }

    Authenticator auth = new SMTPAuthenticator(this.account, this.password);    this.session = Session.getDefaultInstance(this.props, auth);

    this.session.setDebug(this.debug);    this.msg = new MimeMessage(this.session);    try    {      if ((this.from != null) && (!this.from.trim().equals("")))      {        this.msg.setFrom(new InternetAddress(paserEmailAddr(this.from), paserEmailName(this.from), this.strCharSet));      }      else this.msg.setFrom();

      if ((this.to == null) || (this.to.size() == 0)) {        throw new MailException("");      }

      for (Iterator it = this.to.iterator(); it.hasNext(); ) {        String toMail = (String)it.next();        InternetAddress[] address = { new InternetAddress(paserEmailAddr(toMail), paserEmailName(toMail), this.strCharSet) };

        this.msg.addRecipients(Message.RecipientType.TO, address);      }      Iterator it;      if ((this.cc != null) && (this.cc.size() != 0))        for (it = this.cc.iterator(); it.hasNext(); ) {          String ccMail = (String)it.next();          InternetAddress[] address = { new InternetAddress(paserEmailAddr(ccMail), paserEmailName(ccMail), this.strCharSet) };

          this.msg.addRecipients(Message.RecipientType.CC, address);        }      Iterator it;      if ((this.bcc != null) && (this.bcc.size() != 0)) {        for (it = this.bcc.iterator(); it.hasNext(); ) {          InternetAddress[] address = { new InternetAddress((String)it.next()) };

          this.msg.addRecipients(Message.RecipientType.BCC, address);        }      }

      this.msg.setSubject(this.subject, this.strCharSet);

      MimeBodyPart mbp1 = new MimeBodyPart();

      mbp1.setContent(this.content, this.strMailType + ";charset=" + this.strCharSet);

      Multipart mp = new MimeMultipart();      mp.addBodyPart(mbp1);      Iterator it;      if (file != null)      {        for (it = file.iterator(); it.hasNext(); ) {          MimeBodyPart mbp2 = new MimeBodyPart();

          FileDataSource fds = new FileDataSource(it.next().toString().trim());

          mbp2.setDataHandler(new DataHandler(fds));

          mbp2.setFileName(MimeUtility.encodeText(fds.getName(), this.strCharSet, "B"));

          mp.addBodyPart(mbp2);        }

      }

      this.msg.setContent(mp);

      if (this.sendDate == null) this.sendDate = new Date();      this.msg.setSentDate(this.sendDate);

      Transport.send(this.msg, this.msg.getAllRecipients());    }    catch (SendFailedException ex)    {      if ((ex.getCause() instanceof SMTPAddressFailedException)) {        throw new MailException(ex.getCause().getMessage());      }      throw new MailException(ex.getMessage());    }    catch (AddressException ex) {      throw new MailException("AddressException while setting the mail address " + ex.getMessage());    }    catch (MessagingException ex) {      throw new MailException("MessagingException while send the mail  " + ex.getMessage());    }    catch (UnsupportedEncodingException ex) {      throw new MailException("UnsupportedEncodingException while send the mail  " + ex.getMessage());    }  }

发邮件出现IOException和MessagingException如何解决,求大神们帮忙!

服务器返回“550: Invalid User”、“550:local user only”或者“551 delivery not allowed to non-local recipient”。
如果出现在您使用普通方式发送邮件时,这是由于服务器对发件人地址进行检查,对于发件人地址不是由本服务器提供的邮件,不予已发送。
解决的办法是:打开foxmail“帐户属性”中对话框,在“个人信息”的“电子邮件地址”中填写SMTP服务器正确的邮件地址。如果该提示出现在您使用特快专递发送邮件时,则表明对方的邮件服务器不接收这种特快专递的投递方式,请针对这次发送改用普通的方式。

相关标签:大神

下一篇:excel两列数据批量包含查询

上一篇:此时不应有%%adoc命令中输入时显示,但我没输入%%a

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?