我正在尝试使用javamail api发送和发送电子邮件。代码很简单但是当我发送邮件不起作用。显示以下错误消息:
com.sun.mail.smtp.SMTPSendFailedException: 550 5.7.1 Client does not have permissions to send
as this sender
代码是这样的:
public class Email {
static Properties mailServerProperties;
static Session getMailSession;
static MimeMessage generateMailMessage;
static String aInc = "scanner@impresia.es";
public void sendEmail(String a, String c) throws AddressException, MessagingException {
// Server propierties
mailServerProperties = System.getProperties();
mailServerProperties.put("mail.smtp.port", "25");
mailServerProperties.put("mail.smtp.auth", "true");
// New mail
getMailSession = Session.getDefaultInstance(mailServerProperties, null);
generateMailMessage = new MimeMessage(getMailSession);
generateMailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(aInc));
generateMailMessage.setSubject(c);
generateMailMessage.setContent(a, "text/html");
// Send Email
Transport transport = getMailSession.getTransport("smtp");
transport.connect("10.5.32.40", "scanner@impresia.es", "xxxxxxxx");
transport.sendMessage(generateMailMessage, generateMailMessage.getAllRecipients());//generateMailMessage.getAllRecipients());
transport.close();
}
}
拜托,你能帮助我吗?
谢谢!
答案 0 :(得分:0)
您可以尝试在MimeMessage中设置发件人地址后发送邮件。