如何使用Java邮件API保存已发送邮件的邮件?

时间:2013-02-06 13:33:11

标签: java

如何使用Javamail API将已发送的项目保存在邮件中?

props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");

Session session = Session.getInstance(props,new javax.mail.Authenticator() {
    protected PasswordAuthenticationgetPasswordAuthentication() {
        return new PasswordAuthentication("user id","pwd");
    }
});

Message message = new MimeMessage(session);
message.setHeader("X-Priority","1");
message.setFrom(new InternetAddress("user id"));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(Toaddress));

message.addRecipients(Message.RecipientType.CC,InternetAddress.parse(cc));
message.setSubject("Subject");
Multipart multipart = new MimeMultipart();
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("test mail");
Transport.send(message);

2 个答案:

答案 0 :(得分:0)

使用Gmail,您无需将其保存在已发送的文件夹中,Gmail会自动为您执行此操作

答案 1 :(得分:0)

这是解决方案

describe('List controller', function () {

    beforeEach(angular.mock.module('myApp'));

    var $controller, $rootScope, $scope, $state;

    beforeEach(inject(function (_$controller_, _$rootScope_) {
        $controller = _$controller_;
        $rootScope = _$rootScope_;
        $scope = $rootScope.$new();
    }));

    describe('Parameter Group List', function() {
        it('should exists', function () {
            $controller = $controller('baseController', {'$scope': $scope});
            expect($scope.prepareSidebarMenu).toBeDefined();
        });
        it('should exists', function () {
            $state = {};
            $scope.header = {};
            $state.current = {};
            var parameterGroups = '';
            $scope.header.title = '';
            $controller = $controller('listController', {'$scope': $scope, 'parameterGroups': parameterGroups });
            expect($scope.truncateCharacters).toBeDefined();
        });
    });
});