Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 25

Discussione: Form via Email

  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    155

    Form via Email

    Ciao, ho un problema con un form in java, non riesco ad inviare nulla ... uso la libreria:

    import javax.mail.internet.*;

    mi va in eccezione, l'eccezione è:

    MessagingException

    Sicuramente sarà un errore nell'impostazione dell'smtp, questo è il codice:

    Codice PHP:

            
    try {

                
    Properties props System.getProperties();
                
    props.put("mail.smtp.host""smtp.yahoo.it");

                
    props.put("mail.smtp.auth""true");
                
    Session session Session.getDefaultInstance(props);
                
    session.setPasswordAuthentication(new URLName("smtp""smtp.yahoo.it"25"INBOX"userpass), new PasswordAuthentication(userpass));

                
    Message message = new MimeMessage(session);
                
    InternetAddress from = new InternetAddress(this.from);
                
    InternetAddress to[] = InternetAddress.parse(this.to);
                
    message.setFrom(from);
                
    message.setRecipients(Message.RecipientType.TOto);
                
    message.setSubject(this.subject);
                
    message.setSentDate(new java.util.Date());
                
    message.setText(this.body);
                
    message.setContent(this.bodythis.contentType);
                
    Transport tr session.getTransport("smtp");
                
    tr.connect("smtp.yahoo.it"userpass);
                
    message.saveChanges();

                
    tr.sendMessage(messagemessage.getAllRecipients());

                
    tr.close();
                
    System.out.println("E-Mail spedita...");

            } catch (
    MessagingException e) {
                
    System.out.println("Si è verificato un errore nell'invio della dei campi.");
                
    e.getMessage();

            } 
    ovviamente nella riga:

    "INBOX", user, pass), new PasswordAuthentication(user, pass));

    gli passo l'username di yahoo e la password, quindi nome@yahoo.it e pass

  2. #2
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    155

    error

    Ho fatto stampare il messaggio dell'eccezione:

    Could not connect to SMTP host: smtp.yahoo.it, port: 25

  3. #3
    Moderatore di Programmazione L'avatar di LeleFT
    Registrato dal
    Jun 2003
    Messaggi
    17,328
    A me risulta che il server SMTP di Yahoo! sia "smtp.mail.yahoo.it" e non "smtp.yahoo.it".


    Ciao.
    "Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
    Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza

  4. #4
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    155
    si si, anche facendo:

    smtp.mail.yahoo.it

    E-Mail ERRORE: Unknown SMTP host: smtp.mail.yahoo.it

  5. #5
    Originariamente inviato da Angyles
    si si, anche facendo:

    smtp.mail.yahoo.it

    E-Mail ERRORE: Unknown SMTP host: smtp.mail.yahoo.it
    uhm che non sia un errore di battitura della mail che gli dai o di qualche altro campo magari hai dimenticato un punto e virgola con che cosa compili per curiosità io compilo con il dos di windows per il java e mi da pochi errori generalmente e ne sono felice quando sono così pochi

  6. #6
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    155
    Credo aver scritto tutto bene, il codice intero è:

    Codice PHP:

    public class E_MailManager {

        private 
    String to;
        private 
    String from;
        private 
    String subject;
        private 
    String body;
        private 
    String contentType;
        private 
    String user "mioNome";
        private 
    String pass "miaPass";

        
    //Costruttore
        
    public E_MailManager(String toString fromString subjectString body) {
            
    this.to to;
            
    this.from from;
            
    this.subject subject;
            
    this.body body;
            
    this.contentType "text/plain";

        }

        
    //Metodo di invio
        
    public void send() {
            try {
                
    Properties props System.getProperties();
                
    props.put("mail.smtp.host""smtp.mail.yahoo.it");

                
    props.put("mail.smtp.auth""true");
                
    Session session Session.getDefaultInstance(props);
                
    session.setPasswordAuthentication(new URLName("smtp""smtp.mail.yahoo.it"25"INBOX"userpass), new PasswordAuthentication(userpass));

                
    Message message = new MimeMessage(session);
                
    InternetAddress from = new InternetAddress(this.from);
                
    InternetAddress to[] = InternetAddress.parse(this.to);
                
    message.setFrom(from);
                
    message.setRecipients(Message.RecipientType.TOto);
                
    message.setSubject(this.subject);
                
    message.setSentDate(new java.util.Date());
                
    message.setText(this.body);
                
    message.setContent(this.bodythis.contentType);
                
    Transport tr session.getTransport("smtp");
                
    tr.connect("smtp.mail.yahoo.it"userpass);
                
    message.saveChanges();

                
    tr.sendMessage(messagemessage.getAllRecipients());

                
    tr.close();
                
    System.out.println("E-Mail spedita...");
            } catch (
    MessagingException e) {
                
    System.out.println("E-Mail ERRORE: " e.getMessage());
            }
        }

        public 
    void setContentType(String contentType) {
            
    this.contentType contentType;
        }



  7. #7
    Originariamente inviato da Angyles
    Credo aver scritto tutto bene, il codice intero è:

    Codice PHP:

    public class E_MailManager {

        private 
    String to;
        private 
    String from;
        private 
    String subject;
        private 
    String body;
        private 
    String contentType;
        private 
    String user "mioNome";
        private 
    String pass "miaPass";

        
    //Costruttore
        
    public E_MailManager(String toString fromString subjectString body) {
            
    this.to to;
            
    this.from from;
            
    this.subject subject;
            
    this.body body;
            
    this.contentType "text/plain";

        }

        
    //Metodo di invio
        
    public void send() {
            try {
                
    Properties props System.getProperties();
                
    props.put("mail.smtp.host""smtp.mail.yahoo.it");

                
    props.put("mail.smtp.auth""true");
                
    Session session Session.getDefaultInstance(props);
                
    session.setPasswordAuthentication(new URLName("smtp""smtp.mail.yahoo.it"25"INBOX"userpass), new PasswordAuthentication(userpass));

                
    Message message = new MimeMessage(session);
                
    InternetAddress from = new InternetAddress(this.from);
                
    InternetAddress to[] = InternetAddress.parse(this.to);
                
    message.setFrom(from);
                
    message.setRecipients(Message.RecipientType.TOto);
                
    message.setSubject(this.subject);
                
    message.setSentDate(new java.util.Date());
                
    message.setText(this.body);
                
    message.setContent(this.bodythis.contentType);
                
    Transport tr session.getTransport("smtp");
                
    tr.connect("smtp.mail.yahoo.it"userpass);
                
    message.saveChanges();

                
    tr.sendMessage(messagemessage.getAllRecipients());

                
    tr.close();
                
    System.out.println("E-Mail spedita...");
            } catch (
    MessagingException e) {
                
    System.out.println("E-Mail ERRORE: " e.getMessage());
            }
        }

        public 
    void setContentType(String contentType) {
            
    this.contentType contentType;
        }


    provalo a compilare sul prompt dei comandi di windows se sei su windows facendo javac nomefile.java poi java nomefile ovviamente devi saperti muovere nel dos altrimenti puoi provare con i programmi appena sai che errore ti da usando un compilatore serio segnalalo sul post almeno così si cerca di capire il tutto

  8. #8
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    155

    Nessun Errore

    Non da nessun errore, soltanto

    E-Mail ERRORE: Unknown SMTP host: smtp.mail.yahoo.it, cioè lancia l'eccezione non riconoscendo l'smtp.

  9. #9
    Moderatore di Programmazione L'avatar di LeleFT
    Registrato dal
    Jun 2003
    Messaggi
    17,328
    codice:
          try {
             Properties props = System.getProperties();
             props.put("mail.smtp.host", "smtp.mail.yahoo.it");
    
             props.put("mail.smtp.auth", "true");
             Session session = Session.getDefaultInstance(props);
             session.setPasswordAuthentication(new URLName("smtp", "smtp.yahoo.it", 25, "INBOX", user, password), new PasswordAuthentication(user, password));
    
             Message message = new MimeMessage(session);
             InternetAddress from = new InternetAddress( fromStr );
             InternetAddress to[] = InternetAddress.parse( toStr );
             message.setFrom(from);
             message.setRecipients(Message.RecipientType.TO, to);
             message.setSubject("Prova invio mail da Yahoo");
             message.setSentDate(new java.util.Date());
             message.setText("Testo del messaggio che dovrà comparire nella mail.");
    //         message.setContent(this.body, this.contentType);
             Transport tr = session.getTransport("smtp");
             tr.connect("smtp.mail.yahoo.it", user, password);
             message.saveChanges();
    
             tr.sendMessage(message, message.getAllRecipients());
    
             tr.close();
             System.out.println("E-Mail spedita...");
    
          } catch (Exception e) {
             System.out.println("Si è verificato un errore nell'invio della dei campi.");
             e.printStackTrace();
          }
    Ho preso il tuo codice, l'ho adattato con i miei dati di accesso e non ho avuto alcun tipo di problema. La mail è stata spedita correttamente.

    Se ottieni quell'errore allora c'è un problema con i server DNS che tu stai usando.


    Ciao.
    "Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
    Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza

  10. #10
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    155

    email

    come email usi yahoo?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.