无法在 spring 启动应用程序中使用 GMail 服务器

Cannot used GMail server in spring boot application

我不知道这里问的地方是否合适,但无论如何,我正尝试在我的 Spring 引导应用程序中使用 gmail 作为邮件服务器。当我在本地 运行 时,我可以毫无错误地发送邮件。但是当我在我的服务器中部署时。有一个错误。可能是什么问题?

我们已经打开服务器中的所有端口

这是错误报告:糟糕!未找到内容 |无法获取 JDBC 连接;嵌套异常是 org.hibernate.exception.GenericJDBCException:无法获取 JDBC 连接| 500

HTML 脚本:

<form method="GET" action="/contactusSave" class="">
                <div class="form-group">
                    <label for="email">Name</label>
                     <input type="text" class="form-control" id="fname" placeholder="Full Name" name="name">
                </div>
                <div class="form-group">
                    <label for="email">Email</label>
                     <input type="text" class="form-control" id="fname" placeholder="Enter Email" name="email">
                </div>
                <div class="form-group">
                    <label for="email">Subject</label>
                     <input type="text" class="form-control" id="fname" placeholder="Subject" name="subject">
                </div>

                <div class="form-group mt-3">
                    <label for="comment">Description:</label>
                    <textarea class="form-control" rows="5" id="comment" placeholder="Add Description" name="description"></textarea>
                </div>


                 <button class="admin-login-button login-button">Submit</button>
</form>

控制器:

@Controller
@RequestMapping("")
public class DemoController {

@Autowired
JavaMailSender sender;

@RequestMapping(value = "/contactusSave", method = RequestMethod.GET)
    public String contactusSave(@RequestParam("name") String username,
        @RequestParam("email") String email,
        @RequestParam("subject") String subject,
        @RequestParam("description") String description {


    System.out.println("email");
    String email = "*****@gmail.com";
    String body = "From: "+email +"\n" + "Description: "+ description;

    MyHelper.sendMail(sender,email, subject, body);   

    return "redirect:/index";
}

我的帮手Class:

@Service
public class MyHelper {
public static void sendMail(JavaMailSender senders, String mEmail, String messageSubject, String messageBody) {

            SimpleMailMessage msg = new SimpleMailMessage();

            msg.setTo(mEmail);

            msg.setSubject(messageSubject);
            msg.setText(messageBody);
            senders.send(msg);

        }
}

应用程序属性:

spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=****@gmail.com
spring.mail.password=****

#new properties added
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.auth = true;
spring.mail.properties.mail.socketFactory.port=587

spring.mail.properties.mail.socketFactory.class=javax.net.ssl.SSLSocketFacto 里 spring.mail.properties.mail.socketFactory.fallback=假

这是我在应用程序属性文件中添加新属性后收到的新错误消息: 哎呀!未找到内容 |邮件服务器连接失败;嵌套异常是 com.sun.mail.util.MailConnectException:无法连接到主机,端口:smtp.gmail.com,587;超时-1;嵌套异常是:java.net.SocketException:权限被拒绝:连接。失败消息:com.sun.mail.util.MailConnectException:无法连接到主机,端口:smtp.gmail.com、587;超时-1;嵌套异常是:java.net.SocketException:权限被拒绝:连接| 500

问题已解决。服务器中的防病毒软件出现问题。