Results 1 to 4 of 4
- 09-26-2010, 05:32 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 3
- Rep Power
- 0
how to send email from my website?
hi all..
my idea is : sending message from my website by clients to my email.
so what have i done? :D
1- i have created email account in my websit : mail@mywebsite.com to use it for sending.
2- designed jsf pages and manged bean.
but the result is failure! :mad:
please guid me to solve problem.. and sorry for bothering! :(
my files:
1-send.jsp
2- success.jsp "if the operation done"Java Code:<body> <h1><h:outputText value="Hello to send Email to me: "/></h1> <h:form> <h:panelGrid columns="2"> <h:outputText value="Your email: "/> <h:inputText id="_from" value="#{mail1.from}" required="true" size="30"> <f:validateLength minimum="8" maximum="30"/> </h:inputText> <h:outputText value="Your Message: "/> <h:inputTextarea id="msg" cols="30" rows="8" required="true"> <f:validateLength minimum="1"/> </h:inputTextarea> <h:panelGroup/> <h:panelGroup id="buttons"> <h:commandButton type="submit" value="submit" action="#{mail1.sendEmail}"/> <h:commandButton type="reset" value="Reset"/> </h:panelGroup> <h:panelGroup><h:message for="_form" showSummary="true" showDetail="false" style="color:red;"/></h:panelGroup> <h:panelGroup> <h:message for="msg" showSummary="true" showDetail="false" style="color:red;"/> </h:panelGroup> </h:panelGrid> </h:form> </body>
3-fail.jsp "if it fail"Java Code:<body> <h1><h:outputText value="Hello ... It is run!"/></h1> </body>
4- managed bean : mail.javaJava Code:<body> <h1><h:outputText value="not Run!"/></h1> </body>
5- faces-config.xml:Java Code:package JMail; import javax.mail.*; import javax.mail.internet.*; import java.util.*; public class mail { private final String _to = "myEmail"; private final String smtpServer = "smtp.myWebsit.com"; private String _from ; private String msg ,subject; private final String fail_msg = "fail"; private final String suc = "success"; private final String password = "My email [in my website] password"; /** Creates a new instance of mail */ public mail() { } /** * @return the _to */ public String getTo() { return _to; } /** * @return the smtpServer */ public String getSmtpServer() { return smtpServer; } /** * @return the _from */ public String getFrom() { return _from; } /** * @return the msg */ public String getMsg() { return msg; } /** * @param msg the msg to set */ public void setMsg(String msg) { this.msg = msg; } /** * @return the subject */ public String getSubject() { return subject; } /** * @param subject the subject to set */ public void setSubject(String subject) { this.subject = subject; } /** * here method that send email */ public String sendEmail(){ String action ; try{ Properties props = System.getProperties(); props.put("mail.transport.protocol", "smtp" ); props.put("mail.smtp.starttls.enable","true" ); props.put("mail.smtp.host",smtpServer); props.put("mail.smtp.auth", "true" ); Authenticator auth = new SMTPAuthenticator(); Session session = Session.getInstance(props, auth); Message mssg = new MimeMessage(session); // -- Set the FROM and TO fields -- mssg.setFrom(new InternetAddress(_from)); mssg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(_to, false)); mssg.setSubject(subject); mssg.setText(msg); // -- Set some other header information -- mssg.setHeader("MyMail", "Mr. XYZ" ); mssg.setSentDate(new Date()); // -- Send the message -- Transport.send(mssg); System.out.println("Message sent to"+_to+" OK." ); return suc; }catch(Exception ex){ System.out.println("Exception "+ex); return fail_msg; } } /** * @param from the _from to set */ public void setFrom(String from) { this._from = from; } private class SMTPAuthenticator extends javax.mail.Authenticator { @Override public PasswordAuthentication getPasswordAuthentication() { String username = "My Email ID"; return new PasswordAuthentication(username, password); } } }
:oJava Code:<navigation-rule> <navigation-case> <from-outcome>success</from-outcome> <to-view-id>/success.jsp</to-view-id> </navigation-case> <navigation-case> <from-outcome>fail</from-outcome> <to-view-id>/fail.jsp</to-view-id> </navigation-case> </navigation-rule>
- 10-28-2010, 09:26 PM #2
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
can you tell me what's the exception you got
- 10-28-2010, 10:19 PM #3
Member
- Join Date
- Apr 2009
- Posts
- 3
- Rep Power
- 0
:) i solved problem!
i didn't add jar files to server!
thanks a lot for u
- 10-29-2010, 01:00 PM #4
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
simple send email APP, but when press send button appeared:
By lse123 in forum Advanced JavaReplies: 10Last Post: 06-06-2010, 06:49 PM -
how to send an email
By Hussain Ali in forum Advanced JavaReplies: 9Last Post: 03-19-2010, 07:44 AM -
send email using JMS
By Heather in forum Advanced JavaReplies: 9Last Post: 01-07-2009, 03:04 PM -
send email using apache commons email
By jnamendi in forum JavaServer Faces (JSF)Replies: 0Last Post: 10-14-2008, 05:55 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks