简体   繁体   English

在Zimbra服务器中使用javax.mail发送电子邮件

[英]Sending email using javax.mail in zimbra server

I'm using this library to send an email in my university so far I manage to access to the server correctly and to set all my configurations but when I try to send the email I get this error also I tried to put a from address but the server denies me that privilige. 到目前为止,我正在使用该库在大学中发送电子邮件,我设法正确访问服务器并设置了所有配置,但是当我尝试发送电子邮件时,出现此错误,我也尝试输入发件人地址,但是服务器拒绝我特权。 Can anyone tell me what can I do? 谁能告诉我该怎么办? Here is my code and above the error. 这是我的代码,上面的错误。

import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class SendanEmail {

    public static void main(String[] args) {

        final String username = "user";//THIS IS THE SUPPOSE USER I said I alredy got in the server
        final String password = "pass";

        Properties props = new Properties();

        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.host", "smtp.estudiantes.uci.cu");
        props.put("mail.smtp.port", "25");
        props.put("mail.smtp.ssl.trust", "smtp.estudiantes.uci.cu");
        Session session = Session.getInstance(props,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(username, password);
                    }
                });

        try {

            Message message = new MimeMessage(session);
            //message.setFrom(new InternetAddress("ccastro@estudiantes.uci.cu"));
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("ccastro@estudiantes.uci.cu"));
            message.setSubject("Test");
            message.setText("Text content in my email");

            Transport.send(message);

            System.out.println("Done and done");

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
}

And this is the Exception in the program: 这是程序中的异常:

Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: can't determine local email address
    at sendanemail.SendanEmail.main(SendanEmail.java:55)
Caused by: javax.mail.MessagingException: can't determine local email address
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1640)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1194)
    at javax.mail.Transport.send0(Transport.java:254)
    at javax.mail.Transport.send(Transport.java:124)
    at sendanemail.SendanEmail.main(SendanEmail.java:50)
Java Result: 1

Did you try to set the "mail.from" property? 您是否尝试设置“ mail.from”属性?

https://javamail.java.net/nonav/docs/api/ https://javamail.java.net/nonav/docs/api/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM