我创建了一个简单的在线表单,用于通过电子邮件打包和发送信息。我已经习惯了JavaMail API并设法在之前发送电子邮件,但现在我尝试时收到错误。这是发送我的消息的代码(带有一些与消息正文中的信息有关的细节,因为它不适用于我收到的错误)。
/**
* Format the email and send it.
*/
private void Send()
{
this.host = new String("*************");
this.from = new String(text_emailAddress.getText());
this.to = new String ("**************");
this.properties = new Properties();
this.properties.put("mail.transport.protocol", "smtp");
this.properties.put("mail.smtp.host", host);
this.properties.put("mail.smtp.user", "*************");
this.properties.put("mail.smtp.pass", "*************");
this.properties.put("mail.smtp.auth", "true");
this.properties.put("mail.debug", "true");
this.properties.put("mail.smtp.port", "25");
this.session = Session.getDefaultInstance(properties);
this.message = new MimeMessage(session);
try
{
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(*************);
message.setText(this.messageBody);
message.setSentDate(new Date());
MimeMultipart multipart = new MimeMultipart();
BodyPart attachmentBodyPart = new MimeBodyPart();
attachmentBodyPart.setText(createMessageText());
attachmentBodyPart.setFileName(text_customerName.getText() + dateString+".csv");
multipart.addBodyPart(attachmentBodyPart);
message.setContent(multipart, "attachment");
Transport tran = session.getTransport("smtp");
tran.connect("*************", 25, "*************", "*************");
message.saveChanges();
tran.sendMessage(message, message.getAllRecipients());
tran.close();
System.out.println("Message Successfully Sent.");
}
catch(AddressException ae){ ae.printStackTrace(); }
catch(MessagingException me){ me.printStackTrace(); }
}
虽然当我尝试发送邮件时,我收到错误:
javax.mail.MessagingException: Could not connect to SMTP host: *************, port: 25, response: -1
有人知道SMTP服务器的-1响应是什么意思吗?我试过四处寻找,但我似乎无法弄清楚可能导致此错误的原因。这似乎应该可行,并且我使用的IP地址是我在我工作的公司的网络管理员处得到的(尽管它以“10”开头,这听起来并不像外部SMTP地址) 。非常感谢,