Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Java: Общие вопросы > javaMail


Автор: goodday1941 15.6.2007, 01:29
пытаюсь отослать сообщение а оно не пашет выдаает кучу эксепшинов:
отсылаю так:

Код

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

public class msgmultisendsample {
    static String msgText1 = "This is a message body.\nHere's line two.";
    static String msgText2 = "This is the text in the message attachment.";
    public static void main(String[] args) {
        if (args.length != 4) {
            System.out.println("usage: java msgmultisend <to> <from> <smtp> true|false");
            return;
        }
        String to = args[0];
        String from = args[1];
        String host = args[2];
        boolean debug = Boolean.valueOf(args[3]).booleanValue();
        Properties props = new Properties();
        props.put("mail.smtp.host", host);

        Session session = Session.getInstance(props, null);
        session.setDebug(debug);
        try {
            MimeMessage msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(from));

            InternetAddress[] address = {new InternetAddress(to)};

            msg.setRecipients(Message.RecipientType.TO, address);
            msg.setSubject("JavaMail APIs Multipart Test");
            msg.setSentDate(new Date());

            MimeBodyPart mbp1 = new MimeBodyPart();
            mbp1.setText(msgText1);
            MimeBodyPart mbp2 = new MimeBodyPart();
            mbp2.setText(msgText2, "us-ascii");
            Multipart mp = new MimeMultipart();
            mp.addBodyPart(mbp1);
            mp.addBodyPart(mbp2);

            msg.setContent(mp);
            Transport.send(msg);
        } catch (MessagingException mex) {
            mex.printStackTrace();
            Exception ex = null;
            if ((ex = mex.getNextException()) != null) {
                ex.printStackTrace();
            }
        }
    }
}


Стектрейс выдаетследующее:
при входных параметрах: [email protected] [email protected] smtp.gmail.com true
Код

DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 25, isSSL false
220 mx.google.com ESMTP d24sm129900nfh
DEBUG SMTP: connected to host "smtp.gmail.com", port: 25

EHLO ruin
250-mx.google.com at your service, [77.47.128.133]
250-SIZE 28311552
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES
DEBUG SMTP: Found extension "SIZE", arg "28311552"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
530 5.7.0 Must issue a STARTTLS command first d24sm129900nfh
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first d24sm129900nfh

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
    at javax.mail.Transport.send0(Transport.java:169)
    at javax.mail.Transport.send(Transport.java:98)
    at msgmultisendsample.main(msgmultisendsample.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:589)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
QUIT
221 2.0.0 mx.google.com closing connection d24sm129900nfh
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first d24sm129900nfh

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
    at javax.mail.Transport.send0(Transport.java:169)
    at javax.mail.Transport.send(Transport.java:98)
    at msgmultisendsample.main(msgmultisendsample.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:589)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)


при входных параметрах: [email protected] [email protected] smtp.ukr.net true

Код

DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "smtp.ukr.net", port 25, isSSL false
220 ISP UkrNet SMTP.in (storage.ukr.net) ESMTP Fri, 15 Jun 2007 01:32:21 +0300
DEBUG SMTP: connected to host "smtp.ukr.net", port: 25

EHLO ruin
250-storage.ukr.net Hello helix.ntu-kpi.kiev.ua [77.47.128.133]
250-SIZE 26214400
250-8BITMIME
250-PIPELINING
250 HELP
DEBUG SMTP: Found extension "SIZE", arg "26214400"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
250 OK
RCPT TO:<[email protected]>
550 Nastrojki pochtu tut - http://wiki.ukr.net/
DEBUG SMTP: Invalid Addresses
DEBUG SMTP:   [email protected]
DEBUG SMTP: Sending failed because of invalid destination addresses
RSET
DEBUG SMTP: EOF: [EOF]
QUIT
DEBUG SMTP: EOF: [EOF]
javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 Nastrojki pochtu tut - http://wiki.ukr.net/

    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1196)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:584)
    at javax.mail.Transport.send0(Transport.java:169)
    at javax.mail.Transport.send(Transport.java:98)
    at msgmultisendsample.main(msgmultisendsample.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:589)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 Nastrojki pochtu tut - http://wiki.ukr.net/

    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1047)
    ... 9 more
javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
    com.sun.mail.smtp.SMTPAddressFailedException: 550 Nastrojki pochtu tut - http://wiki.ukr.net/

    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1196)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:584)
    at javax.mail.Transport.send0(Transport.java:169)
    at javax.mail.Transport.send(Transport.java:98)
    at msgmultisendsample.main(msgmultisendsample.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:589)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 Nastrojki pochtu tut - http://wiki.ukr.net/

    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1047)
    ... 9 more
com.sun.mail.smtp.SMTPAddressFailedException: 550 Nastrojki pochtu tut - http://wiki.ukr.net/

    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1047)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:584)
    at javax.mail.Transport.send0(Transport.java:169)
    at javax.mail.Transport.send(Transport.java:98)
    at msgmultisendsample.main(msgmultisendsample.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:589)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)



где ошибка? (:

Автор: redrick 15.6.2007, 03:02
мне думается у тебя properties неправильные, попробуй 
Код

Properties props = System.getProperties();

Автор: goodday1941 15.6.2007, 09:40
пробвал и такой вариант уже

у мну четыре варианта рассыльщика сейчас есть.. не один не пашет!

Автор: kkorsakoff 15.6.2007, 11:03
Ну с первым все понятно, smtp-шник требует использования STARTTLS. Это шифрование передаваемых писем. Работает ли с ним JavaMail не могу сказать, возможно что-то можно и нагуглить по этому поводу.

Со вторым странно. В коде ошибок никаких не видно. Понятно, что не нравится ему адрес получателя. Может просто сервер не любит, когда шлешь письма от самого себя себе же?

Автор: hedgehog77 15.6.2007, 13:37
По поводу SMTP на gmail - он требует TLS и авторизации:
Код

// доп. свойства
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");

// получаем транспорт и коннектимся с авторизацией
Transport transport = session.getTransport("smtp");
transport.connect(host, port, "yourlogin", "yourpass");

// посылаем письмо
transport.send(msg);



Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)