繁体   English   中英

从Brinkster托管帐户使用Java发送邮件

[英]Sending mail with java from a brinkster hosted account

我需要使用Java从Brinkster托管帐户发送电子邮件。 我使用此代码从我的gmail acoount发送电子邮件,并且工作正常。

    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class",
            "javax.net.ssl.SSLSocketFactory");        
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "465");

    Session session = Session.getDefaultInstance(props,
            new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {

                    return new PasswordAuthentication("gmailuser", "password");

                }
            });

    try {

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("gmailuser@gmail.com"));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("someone@gmail.com"));

        message.setSubject("subject");
        message.setText("text");

        Transport.send(message);catch (MessagingException e) {
        throw new RuntimeException(e);
    }catch (MessagingException e) {
        throw new RuntimeException(e);
    }

现在,我需要从username@company.com.co发送电子邮件。

    Properties props = new Properties();
    props.put("mail.smtp.host", "mymail.brinkster.com");     //<--changed this
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class",
            "javax.net.ssl.SSLSocketFactory");        
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "465");

    Session session = Session.getDefaultInstance(props,
            new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {

                    return new PasswordAuthentication("username@company.com.co", "password");      //<--changed this

                }
            });

    try {

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("username@company.com.co"));     //<--changed this
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("someone@gmail.com"));

        message.setSubject("subject");
        message.setText("text");

        Transport.send(message);

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

这是行不通的。 我究竟做错了什么? 我认为这可能与smtp.host有关,但我不知道是什么。

我可以知道您遇到的异常类型吗

每个主机都有不同的名称(mail.smtp.host)确保您的主机名正确

并且在gmail中,无论您提供的是哪个地址,它都不会显示为来自地址

暂无
暂无

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

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