1

I'm trying to send email trought the contact me form but IS NOT SENDING I REALLY NEED HELP, I DON'T GET ANY ERROR BUT THE EMAIL IS NOT SENDING. I was tried several times I don't know where the problem is, I'm not getting any error,

    CONSOLE PRINT:

    DEBUG: JavaMail version 1.4.7
    DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
    DEBUG: Tables of loaded providers
    DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
    DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
    DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
    DEBUG SMTP: useEhlo true, useAuth true
    DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false
    220 smtp.gmail.com ESMTP p4-20020a5d48c4000000b00225239d9265sm13649836wrs.74 - gsmtp
    DEBUG SMTP: connected to host "smtp.gmail.com", port: 587
    
    EHLO dembas-mbp.home
    250-smtp.gmail.com at your service, [85.138.51.207]
    250-SIZE 35882577
    250-8BITMIME
    250-STARTTLS
    250-ENHANCEDSTATUSCODES
    250-PIPELINING
    250-CHUNKING
    250 SMTPUTF8
    DEBUG SMTP: Found extension "SIZE", arg "35882577"
    DEBUG SMTP: Found extension "8BITMIME", arg ""
    DEBUG SMTP: Found extension "STARTTLS", arg ""
    DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
    DEBUG SMTP: Found extension "PIPELINING", arg ""
    DEBUG SMTP: Found extension "CHUNKING", arg ""
    DEBUG SMTP: Found extension "SMTPUTF8", arg ""
    STARTTLS
    220 2.0.0 Ready to start TLS

POM.XML

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.itconnectstartup</groupId>
  <artifactId>itconnectbackend</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <name>itconnectbackend</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
        <spring.version>4.3.6.RELEASE</spring.version>

  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    
    <!-- SPRING MVC DEPENDENCY -->
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        
    <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>5.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
            
            
        </dependency>
    <!-- https://mvnrepository.com/artifact/javax.mail/javax.mail-api -->
<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>javax.mail-api</artifactId>
    <version>1.6.2</version>
</dependency>


  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
    
    <plugins>
            <!-- UPDATE TO LATEST JAVA -->
            <plugin>

                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
    </plugins>
  </build>
</project>

dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc.xsd
   
   ">
   
   <context:component-scan base-package="com.itconnectstartup.controller"/>
   <context:component-scan base-package="com.itconnectstartup.itconnectbackend"/>
 
  
   
   <bean id="viewResolver"
   class="org.springframework.web.servlet.view.InternalResourceViewResolver">
   <property name="prefix" value="/WEB-INF/views/"/>
   
   <property name="suffix" value=".jsp"/>
   
   </bean>
   
   <!-- loading statics resources -->
   <mvc:annotation-driven/>
    <mvc:resources location="/resources/" mapping="resources/**"/>
    
    <!-- Production implementation of the JavaMailSender interface, supporting 
        both JavaMail MimeMessages and Spring SimpleMailMessages -->
        
    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="smtp.gmail.com" />
        <property name="port" value="587" />
        <property name="username" value="bubacar76@gmail.com" />
        <property name="password" value="rboouqsjhcregdjq" />
        <!-- The name of the property, following JavaBean naming conventions -->
        <property name="javaMailProperties">
            <props>
                <prop key="mail.transport.protocol">smtp</prop>
                <prop key="mail.smtp.auth">true</prop>
                <prop key="mail.smtp.starttls.enable">true</prop>
                <prop key="mail.debug">true</prop>
            </props>
        </property>
    </bean>
    
</beans>

contact.java

package com.itconnectstartup.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.itconnectstartup.itconnectbackend.dao.ContactDAO;
import com.itconnectstartup.itconnectbackend.dto.Contact;




@Controller
@RequestMapping("contact")
public class ContactController {
    
    
    @Autowired 
    private ContactDAO contactDAO;
    
    @RequestMapping(method=RequestMethod.GET )
    public ModelAndView page(ModelMap model) {
        
        model.put("contact", new Contact());
        
        ModelAndView modelandview=new ModelAndView("page");

        modelandview.addObject("title","contact");
        modelandview.addObject("userclickcontact",true);
        
        return modelandview;
            
    }
    
        
    
    
    
    @RequestMapping(value="send", method=RequestMethod.POST)
    public ModelAndView send(@ModelAttribute("contact") Contact contact, ModelMap model) {
        
        ModelAndView modelandview=new ModelAndView("page");
        try {
            
            String content="Name: "+ contact.getName()+" ";
            content+=" Last Name: "+ contact.getLastName();
            content+=" Email: "+ contact.getEmail();
            content+=" Tel: "+ contact.getTel();
            content+=" Message: "+ contact.getMessage();
            
            contactDAO.send(contact.getEmail(),"bubacar76@gmail.com",contact.getMessage(),content);
            modelandview.addObject("msg","done!");
            modelandview.addObject("emailsent",true);
        }catch(Exception e) {
            
            model.put("errors", "error goes on");
            
        }
        
        
        modelandview.addObject("title","contact");
        modelandview.addObject("userclickcontact",true);
        
        
        return modelandview;
        
    }

}

contact.jsp

<%@taglib prefix="sf" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>






<div class="container-fluid">


<c:if test="${emailsent==true}">

        ${msg}
        <script type="text/javascript">
        
        $(document).ready(function () {
            
            $('#IDName').val('');
            $('#IDLastName').val('');
            $('#IDMobile').val('');
            $('#IDEmail').val('');
            $('#IDMessage').val('');
            
            
            Swal.fire(
                      'Email sent',
                      'Your email has been sent successfully, Thank you for getting in touch with us!',
                      'success'
                    
                    )
                
                
            
        });
        </script>
        </c:if>
        
        
        

    <div class="row">
    
        <div class="col col-lg-12">
        ${hello}
            <h2 class="contact_title">Contact us</h2>

        </div>

    </div>


    <div class="row">

        <div class="col-xs-12 col-lg-6 col-md-12 col-sm-12">    
            <sf:form class="validation_contact" method="post"  modelAttribute="contact" action="${contextRoot}/contact/send">
                <div class="row">
                    <div class="col">
                        <sf:input type="text" path="name" class="form-control" placeholder="first name" id="IDName" required="required"/>
                    </div>
                    <div class="col">
                        <sf:input type="text" path="lastName" class="form-control" placeholder="last name" id="IDLastName" required="required"/>
                    </div>

                    <div class="col">
                        <sf:input type="tel" path="tel" class="form-control" placeholder="mobile number" id="IDMobile" required="required"/>
                    </div>
                </div>
                <br>
                <div class="row">
                    <div class="col">
                        <sf:input type="email" path="email" class="form-control" placeholder="email" id="IDEmail" required="required"/>
                    </div>

                </div>
                <br>
                <div class="row">
                
                    <label for="exampleFormControlTextarea1"
                        class="exampleFormControlTextarea1">Message</label>
                    <sf:textarea path="message" class="form-control simple_style_textarea"
                        id="IDMessage" rows="5" required="required"></sf:textarea>
                </div>
                <br>
                <button class="btn btn-primary" type="submit">Send</button>
                <br><br>
            </sf:form>
     <!-- end div row./ form -->
        </div>
        
     
        <div class="mapouter col-lg-6 col-sm-12 col-xs-12 center" style="height: 300px">
        <div class="gmap_canvas"  style="height: 300px;"
        ><iframe width="600" height="300" id="gmap_canvas" src="https://maps.google.com/maps?q=avenida%20louren;o%20marques%208&t=&z=19&ie=UTF8&iwloc=&output=embed" frameborder="0" scrolling="no" marginheight="0" marginwidth="0">
        </iframe><br>
        <style>.mapouter{position:relative;text-align:right;height:500px;width:600px;}
        </style>
        <style>
        .gmap_canvas {overflow:hidden;background:none!important;height:500px;width:600px;}
        </style></div></div>
        <hr>
        
    </div><!-- end row  -->
    
    
    
    <br>
    <div class="row" style="background-color:">
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-6">
<div>
     <!-- /div first images services  -->
<img alt="" class=" main_img_services img-fluid" src="${contextRoot}/resources/images/capa_desenv.png">
</div>
    
    </div>

<div class="col-xs-12 col-sm-12 col-md-12 col-lg-6">
<div class="some_extra_desc" style="background-color:#000">
<p class="extra_desc" style="font-size: 20px; color:#b6b7b9; margin:10px;">Take with you a greater experience at the high technologycal level, 
our nickname is work accompanied by successes, we will transform 
your ideas into digital solutions, our services are guaranteed, if your reason is
innovation you are in right place.</p>

<!-- /div some extra desc -->
</div>




<div data-aos="fade-up"
     data-aos-anchor-placement="center-bottom">
     <!-- /div first images services  -->
<img alt="" class=" main_img_services img-fluid" src="${contextRoot}/resources/images/tech_proj.png">
</div>

</div>

</div>
    <br><br>
    
    
    <div class="row">
    <div class="col col-lg-6 col-md-12 col-xs-12 col-sm-12">
    <h3 class="addressInfo_title">ITconnect</h3>
    <p class="address_Text" style="margin: 0;font-family: 'Questrial', sans-serif; font-size:20px;">Avenida lourenço marques 08 3TO 2700-527</p>
    <p class="telefone_text" style="margin: 0;font-family: 'Questrial', sans-serif;font-size:20px;">Tel: +351 92010-5855</p>
    <p class="email_info" style="margin: 0;font-family: 'Questrial', sans-serif;font-size:20px;">Email: itconnect@startup.com </p>
     
    
    <!-- end/ div col address  -->
    </div>
    
    <!--end div row address -->
    
    
    <div class="col col-lg-6 col-md-12 col-xs-12 col-sm-12">
    
    <div class="background_reverse_black">
 <img alt="" class=" main_i img-fluid" src="${contextRoot}/resources/images/logoitconnect.png">
  </div>
  
  <p class="desc_itconnect" style="font-family: 'Questrial', sans-serif; font-size:20px;">Do not hesitate to contact us, 
  we are available 24/24 hours, 
  we will respond as soon as possible,
  <br> <h6>Your team ITconnect.</h6></p>
    
    <!-- end/ div col address  -->
    </div>
    </div>
    
    <!-- simple footer  -->
<br><br><br><br>

contactDAOimpl.java

package com.itconnectstartup.itconnectbackend.daoimpl;
import javax.mail.internet.MimeMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import com.itconnectstartup.itconnectbackend.dao.ContactDAO;
@Service("contactDAO")
public class ContactDAOimpl implements ContactDAO{
    @Autowired 
    private JavaMailSender mailSender;
    
    @Override
    public void send(String fromAddress, String toAddress, String subject, String content) throws Exception {       
        MimeMessage contactMSG = mailSender.createMimeMessage();
        MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(contactMSG,true);
        mimeMessageHelper.setFrom(fromAddress);
        mimeMessageHelper.setTo(toAddress);
        mimeMessageHelper.setSubject(subject);
        mimeMessageHelper.setText(content,true);
        mailSender.send(contactMSG);
    }

}
Demba
  • 21
  • 2

0 Answers0