2012-09-20 3 views
7

sto usando puntone 2.0 hibernate 3.0 e tiles 3.0 per il mio sito Web e voglio inviare mail a [email protected] ma non sono in grado di inviare mail su quello quindi cosa ho da fare .....configurazione email del sito web in java utilizzando puntoni

http://shreerajinvestment.com/Home/send_feedback.action

package admin; 

import java.util.Properties; 

import javax.mail.Message; 
import javax.mail.PasswordAuthentication; 
import javax.mail.Session; 
import javax.mail.Transport; 
import javax.mail.internet.InternetAddress; 
import javax.mail.internet.MimeMessage; 

public class SendMailFeedback { 
    private String from; 
    private String to; 
    //private String cc; 
    private String subject; 
    private String password; 
    private String text; 

    public SendMailFeedback(String from, String to, String subject, String text, String password) 
    { 
     this.from = from; 
     this.to = to; 
     //this.cc = cc; 
     this.subject = subject; 
     this.text = text; 
     this.password = password; 
    } 

    public void send() throws Exception 
    { 
     System.out.println("Send FeedBack"); 
     try 
     { 
      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(from,password);}}); 

      Message message = new MimeMessage(session); 
      message.setFrom(new InternetAddress(from)); 
      message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to)); 
      //message.setRecipients(Message.RecipientType.CC,InternetAddress.parse(cc)); 
      message.setSubject(subject); 
      //String link="www.shreerajinvestments.com"; 
      message.setText(text); 
      System.out.println("MAIL"); 
      Transport.send(message); 
     } 
     catch(Exception e) 
     { 
      e.printStackTrace(); 
     } 
    } 
} 

package admin; 

import com.opensymphony.xwork2.ActionSupport; 

public class sendFeedback extends ActionSupport 
{ 
    private static final long serialVersionUID = 1L; 

    private String name; 
    private String email1; 
    private String sub; 
    private String msg; 
    private String contact; 

    public String getName() { 
     return name; 
    } 
    public void setName(String name) { 
     this.name = name; 
    } 

    public String getEmail1() { 
     return email1; 
    } 
    public void setEmail1(String email1) { 
     this.email1 = email1; 
    } 
    public String getSub() { 
     return sub; 
    } 
    public void setSub(String sub) { 
     this.sub = sub; 
    } 
    public String getMsg() { 
     return msg; 
    } 
    public void setMsg(String msg) { 
     this.msg = msg; 
    } 
    public String getContact() { 
     return contact; 
    } 
    public void setContact(String contact) { 
     this.contact = contact; 
    } 

    String re; 

    public String execute() throws Exception 
    { 
     System.out.println("Send FeedBack"); 
     try 
     { 
       addActionMessage("Your FeedBack is Send Successfully"); 

       String from = "[email protected]"; 
       String to = "[email protected]"; 

       String subject = sub; 
       String text = "This Mail from http://www.shreerajinvestment.com/ \n\nThis FeedBack From : \n\n \t\t Sender Name :" + name + "\n\n\t\t Sender Email ID :" + email1 + "\n\n\t\t Sender Contact No. :" + contact + "\n\n\t\t" + msg; 
       String password = "my password"; 

       SendMail SendMail = new SendMail(from, to, subject, text, password); 
       SendMail.send(); 

       re=SUCCESS; 
     } 
     catch(Exception ex) 
     { 
      System.out.println("Connection Failed: "+ex); 
      ex.printStackTrace(); 
     } 
     return re; 
    } 
} 
+0

quello eccezione vuoi arrivare? –

+0

Voglio anche conoscere il tuo errore più in dettaglio. – swemon

risposta

1

se si colpisce l'UnknownHostException: smtp.gmail.com, provare a ping smtp.gmail.com e assicurarsi che hai una risposta (in grado di accedere). Spesso, la tua connessione potrebbe bloccarsi dal tuo firewall o proxy. Altrimenti hai bisogno di javaee.jar e mail.jar nel tuo classpath.
Cin cin ...

+0

non ricevo alcun errore .... quando lo eseguo dal server locale ma il mio sito sul web in quel momento non riesco a ottenere una risposta adeguata e inoltre non ricevo posta su [email protected] –

+0

prova ping smtp.gmail.com e assicurati di avere una risposta –

+0

e io sono nuovo per caricare il sito web e configurarlo su web, in modo da darmi una soluzione di dettaglio ..... –

0

Si prega di provare per questa proprietà di posta elettronica. Controlla che la tua posta invii correttamente.

Properties props = new Properties(); 
props.put("mail.smtp.host", "smtp.gmail.com"); 
props.put("mail.smtp.starttls.enable", "true"); 
props.put("mail.smtp.auth", "true"); 
props.put("mail.smtp.port", "587"); 
+0

grazie molto swemon –