Results 1 to 10 of 21

Thread: problem sending an email with javamail

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default problem sending an email with javamail

    Hello guys
    i need really your help, my boss have a gun and .... i want to live,
    i cant send a simple email
    this is my xml configuration

    Code:
    <beans>
    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> 
       <property name="host"> 
       	<value>mail.yahoo.com</value>
        </property>
        <property name="username" >
       	<value>usernamesenderyahoo</value> <!-- same result if i write with @yahoo.com-->
        </property>
        <property name="password">
    	 <value>passwordsenderyahoo</value>
        </property>		    	    
        <property name="javaMailProperties">
            <props>
    	  <prop key="mail.smtp.auth">true</prop>
            </props>
        </property>
    </bean>
    		
    <bean id="messageSender" class="com.test.ComplexMessageSender" >
       <property name="javaMailSender">
    	<ref local="mailSender"/>
       </property>
       <property name="to">
    	<value>emailaddressdestination@hotmail.com</value>
       </property>
       <property name="from">
    	<value>usernamesenderyahoo@yahoo.com</value>
       </property>
       <property name="subject">
    	<value>Spring mail</value>
       </property>						
    </bean>			  
    </beans>
    when i start up the tomcat 5.5.27, by "ant" i execute a java class that call a bean

    Code:
    ComplexMessageSender plex = (ComplexMessageSender) ctx.getBean("messageSender");			
    plex.sendMessage();
    so after almost 3-5 minutes i recieve this prize

    Code:
     [java]    [java] EXCPETIONMail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: mail.yahoo.com, port: 25;
         [java] nested exception is:
         [java] java.net.ConnectException: Connection timed out
         [java] Stack
         [java] CLASEclass org.springframework.mail.MailSendException
         [java] org.springframework.mail.MailSendException; nested exceptions (0) are:
         [java] Caused by: javax.mail.MessagingException: Could not connect to SMTP host: mail.yahoo.com, port: 25;
         [java] nested exception is:
         [java] java.net.ConnectException: Connection timed out
         [java] at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1213)
         [java] at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:311)
         [java] at javax.mail.Service.connect(Service.java:233)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:373)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:326)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:341)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:330)
         [java] at com.test.ComplexMessageSender.sendMessage(Unknown Source)
         [java] at Manolo.pruebas(Unknown Source)
         [java] at Manolo.main(Unknown Source)
    BUILD SUCCESSFUL
    Total time: 5 minutes 17 seconds
    or the second prize is this
    Code:
     [java] EXCPETIONAuthentication failed; nested exception is javax.mail.AuthenticationFailedException
         [java] Stack
         [java] CLASEclass org.springframework.mail.MailAuthenticationException
         [java] org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException
         [java] Caused by: javax.mail.AuthenticationFailedException
         [java] at javax.mail.Service.connect(Service.java:264)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:373)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:326)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:341)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:330)
         [java] at com.test.ComplexMessageSender.sendMessage(Unknown Source)
         [java] at Manolo.pruebas(Unknown Source)
         [java] at Manolo.main(Unknown Source)
    i dont have any idea what could be wrong
    plse help!!!

    thanks for advanced
    Last edited by dr_pompeii; Jan 16th, 2007 at 09:45 AM.
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  2. #2

    Default

    Just to be sure, have you tried to connect to SMTP server using telnet ?
    (http://www.yuki-onna.co.uk/email/smtp.html)

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I don't know if yahoo will play nicely or not. I have used gmail successfully before, but these services are sometimes changed from time to time to prevent spam and such like. I would google the problem, there are lots of responses out there.

    e.g.
    http://forum.java.sun.com/thread.jspa?threadID=244595
    http://saloon.javaranch.com/45/000783.html

  4. #4
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello guys
    thanks for your reply both
    well by order

    pgras
    thanks again
    i saw your link so, if i try in linux this

    Code:
    well after a long delay i recieve again these prize 
    [user@localhost ~]$ telnet mail.yahoo.com 25
    Trying 209.191.92.114...
    telnet: connect to address 209.191.92.114: Connection timed out
    telnet: Unable to connect to remote host: Connection timed out
    [user@localhost ~]$
    or
    [user@localhost ~]$ telnet gmail.com 25 <---- check the way
    Trying 216.239.57.83...
    telnet: connect to address 216.239.57.83: Connection timed out
    Trying 64.233.161.83...
    
    [user@localhost ~]$ telnet mail.gmail.com 25 <---- no work!
    Trying 216.239.57.83...
    telnet: connect to address 216.239.57.83: Connection timed out
    Trying 64.233.161.83...
    telnet: connect to address 64.233.161.83: Connection timed out
    Trying 64.233.171.83...
    so the obvious way , no work , sad but true

    only works for hotmail
    Code:
    [user@localhost ~]$ telnet mail.hotmail.com 25
    Trying 65.54.244.8...
    Connected to mail.hotmail.com (65.54.244.8).
    Escape character is '^]'.
    220 bay0-mc6-f18.bay0.hotmail.com Sending unsolicited commercial or bulk e-mail to Microsoft's computer network is prohibited. Other restrictions are found at http://privacy.msn.com/Anti-spam/. Violations will result in use of equipment located in California and other states. Tue, 16 Jan 2007 17:31:59 -0800
    Connection closed by foreign host.
    like playing
    i found that in these ways works
    Code:
    [user@localhost ~]$ telnet smtp.gmail.com 25
    Trying 66.249.83.109...
    Connected to smtp.gmail.com (66.249.83.109).
    Escape character is '^]'.
    220 mx.google.com ESMTP i35sm12344483wxd
    
    [user@localhost ~]$  telnet smtp.mail.yahoo.com 25
    Trying 68.142.203.143...
    Connected to smtp.mail.yahoo.com (68.142.203.143).
    Escape character is '^]'.
    220 smtp106.plus.mail.mud.yahoo.com ESMTP
    quit
    221 smtp106.plus.mail.mud.yahoo.com
    Connection closed by foreign host.
    [user@localhost ~]$
    now with this configuration for gmail
    Code:
    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> 
        <property name="host"> 
        	<value>smtp.gmail.com</value>
        </property>
        <property name="port"> 
        	<value>25</value>
        </property>
        <property name="username" >
        	<value>usernameforgamil</value>
        </property>
        <property name="password">
    	<value>billgateslovejava</value>
        </property>		    	    
        <property name="javaMailProperties">
            <props>
    	  <prop key="mail.smtp.auth">true</prop>
      	</props>
        </property>
    </bean>
    		
    <bean id="messageSender" class="com.test.ComplexMessageSender" >
    	<property name="javaMailSender">
    		<ref local="mailSender"/>
    	</property>
    	<property name="to">
    		<value>to@hotmail.com</value>
    	</property>
    	<property name="from">
    		<value>usernameforgamil@gmail.com</value>
    	</property>
    	<property name="subject">
    		<value>Spring mail</value>
    	</property>						
    </bean>
    i recieve this

    Code:
    [java] EXCPETIONFailed messages: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first i20sm12364936wxd
         [java] Stack
         [java] org.springframework.mail.MailSendException; nested exception details (1) are:
         [java] Failed message 1:
         [java] com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first i20sm12364936wxd
         [java] at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1275)
         [java] at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:895)
         [java] at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:524)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:382)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:326)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:341)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:330)
         [java] at com.test.ComplexMessageSender.sendMessage(Unknown Source)
         [java] at Manolo.pruebas(Unknown Source)
         [java] at Manolo.main(Unknown Source)
         [java] CLASEclass org.springframework.mail.MailSendException
    for yahoo configuration, i recieve this
    Code:
         [java] EXCPETIONAuthentication failed; nested exception is javax.mail.AuthenticationFailedException
         [java] Stack
         [java] org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException
         [java] Caused by: javax.mail.AuthenticationFailedException
         [java] at javax.mail.Service.connect(Service.java:264)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:373)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:326)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:341)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:330)
         [java] at com.test.ComplexMessageSender.sendMessage(Unknown Source)
         [java] at Manolo.pruebas(Unknown Source)
         [java] at Manolo.main(Unknown Source)
         [java] CLASEclass org.springframework.mail.MailAuthenticationException
    Dear friend karldmoore
    how always thanks for your time and the links
    i saw the javaranch, so i have already open the SMTP (for incoming request, i can find the inverse - out, i use firestarter in FC5)

    but i still have the circus of error.

    pls help!!!

    BTW
    for hotmail i recieve this
    Code:
        [java] EXCPETIONAuthentication failed; nested exception is javax.mail.AuthenticationFailedException
         [java] Stack
         [java] CLASEclass org.springframework.mail.MailAuthenticationException
         [java] org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException
         [java] Caused by: javax.mail.AuthenticationFailedException
         [java] at javax.mail.Service.connect(Service.java:264)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:373)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:326)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:341)
         [java] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:330)
         [java] at com.test.ComplexMessageSender.sendMessage(Unknown Source)
         [java] at Manolo.pruebas(Unknown Source)
         [java] at Manolo.main(Unknown Source)
    regards
    Last edited by dr_pompeii; Jan 16th, 2007 at 08:00 PM. Reason: i forgot exception for hotmail
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  5. #5
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I'd try googling this an going through the results. As I said before, they do mess with the settings on these things. I've had gmail working one week and not the next, very frustrating.

  6. #6
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello karldmoore

    As I said before, they do mess with the settings on these things.
    jesus, i must shoot them

    I've had gmail working one week and not the next, very frustrating.
    really very frustrating., each count should has an option to let send by java mail (to avoid possible false spams) - a solution

    i had an old project with java mail 2 years ago, but without Spirng, and always works, was with a count in http://www.cwazy.net/, (see its features ), i never had problems with that, but now is not free anymore

    maybe other member of the forum use other server for email , and share a link

    thanks for advanced
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  7. #7
    Join Date
    Aug 2010
    Posts
    3

    Unhappy

    please help i did everything correctly in it i have both mail.jar and activaion.jar in the required java directory but still i'm getting this error

    23:32:40,890 ERROR org.springframework.osgi.context.support.OsgiBundl eXmlApplicationContext:307 - Post refresh error
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'mailSender' defined in URL [bundleentry://4.fwk32745991/META-INF/spring/spring.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/mail/MessagingException
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.instantiateBean(Abstrac tAutowireCapableBeanFactory.java:883)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Abst ractAutowireCapableBeanFactory.java:839)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:440)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:429)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:728)
    at org.springframework.osgi.context.support.AbstractD elegatedExecutionApplicationContext.completeRefres h(AbstractDelegatedExecutionApplicationContext.jav a:288)
    at org.springframework.osgi.extender.internal.depende ncies.startup.DependencyWaiterApplicationContextEx ecutor$CompleteRefreshTask.run(DependencyWaiterApp licationContextExecutor.java:145)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NoClassDefFoundError: javax/mail/MessagingException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unk nown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.getDeclaredConstructor(Unknown Source)
    at org.springframework.beans.factory.support.SimpleIn stantiationStrategy.instantiate(SimpleInstantiatio nStrategy.java:54)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.instantiateBean(Abstrac tAutowireCapableBeanFactory.java:877)
    ... 15 more
    Exception in thread "SpringOsgiExtenderThread-36" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'mailSender' defined in URL [bundleentry://4.fwk32745991/META-INF/spring/spring.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/mail/MessagingException
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.instantiateBean(Abstrac tAutowireCapableBeanFactory.java:883)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Abst ractAutowireCapableBeanFactory.java:839)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:440)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:429)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:728)
    at org.springframework.osgi.context.support.AbstractD elegatedExecutionApplicationContext.completeRefres h(AbstractDelegatedExecutionApplicationContext.jav a:288)
    at org.springframework.osgi.extender.internal.depende ncies.startup.DependencyWaiterApplicationContextEx ecutor$CompleteRefreshTask.run(DependencyWaiterApp licationContextExecutor.java:145)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NoClassDefFoundError: javax/mail/MessagingException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unk nown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.getDeclaredConstructor(Unknown Source)
    at org.springframework.beans.factory.support.SimpleIn stantiationStrategy.instantiate(SimpleInstantiatio nStrategy.java:54)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.instantiateBean(Abstrac tAutowireCapableBeanFactory.java:877)
    ... 15 more


    urgent plzz help anyone

  8. #8
    Join Date
    Mar 2009
    Location
    Chicago, USA
    Posts
    10

    Default

    Caused by: java.lang.NoClassDefFoundError: javax/mail/MessagingException

    are the jars on your classpath?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •