Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Spring和AngularJS发送电子邮件?_Java_Angularjs_Spring_Email_Jakarta Mail - Fatal编程技术网

Java 使用Spring和AngularJS发送电子邮件?

Java 使用Spring和AngularJS发送电子邮件?,java,angularjs,spring,email,jakarta-mail,Java,Angularjs,Spring,Email,Jakarta Mail,我不知道该怎么办。我已经搜索了很多教程和指南,但没有一个是有效的。我不知道为什么,但我认为它们已经过时了,这使得事情变得如此复杂 我有一个Maven项目,它使用AngularJS和Spring。我希望使用Gmail作为我的发件人。根据我的研究,在使用ng click $scope.sendEmail = function(){ $scope.emailData.to = "to@gmail.com"; $scope.emailData.subject = "For

我不知道该怎么办。我已经搜索了很多教程和指南,但没有一个是有效的。我不知道为什么,但我认为它们已经过时了,这使得事情变得如此复杂

我有一个Maven项目,它使用AngularJS和Spring。我希望使用Gmail作为我的发件人。根据我的研究,在使用
ng click

$scope.sendEmail = function(){
        $scope.emailData.to = "to@gmail.com";
        $scope.emailData.subject = "Forgot Password";
        $scope.emailData.body = "Description here"

        EmailService.sendEmail($scope.emailData).then(function (response) {
            if(response.status=200){
                //sweetalert here
            }
        });


    }
我的
电子邮件服务是

angular.module('EmailService', []).factory('EmailService', ["$http", function ($http) {
    return {
        sendEmail: function (email) {
            return $http.post("/email/", email).then(function successCallback(response) {

                return response;
            }, function errorCallback(response) {
                return response;
                //error
            })
        },

    }
}])
我的Java中有一个控制器,如下所示:

@RestController
@RequestMapping("/email")
public class EmailController {

    @Autowired
    EmailServiceImpl emailService;

    @RequestMapping( method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public Email sendEmail(@RequestBody Email email) {
        return emailService.create(email);
    }
 }
Email.java
包含

    private String toAddress;
    private String subject;
    private String body;
使用getter和setter,我的
EmailServiceImpl.java

@Service("emailService")
public class EmailServiceImpl {

    public Email create(Email email) {

        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost("smtp.gmail.com");
        mailSender.setPort(587);

        mailSender.setUsername("my.gmail@gmail.com");
        mailSender.setPassword("password");

        Properties props = mailSender.getJavaMailProperties();
        props.put("mail.transport.protocol", "smtp");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.debug", "true");


        return email;
    }
}
那么接下来呢


注意:我使用的是
JPA
,我使用的是
1.5.6.RELEASE
版本。

您可以使用Spring的JavaMailSender接口,在这里您可以学习如何使用它:任何关于如何使用AngularJS的指南?这是一个关于使用AngularJS的RESTFul服务的指南:如果您刚刚使用AngularJS,并且想了解更多,查看课程中的这门课程。顺便说一句,你没有真正的问题,也可以查看这篇:编辑的文章。我的代码旁边是什么?