使用SMTP注销GMail帐户

时间:2013-03-24 15:08:19

标签: android smtp javamail logout

我正在使用SMTP发送邮件。发送邮件效果很好。但是,我想在按钮点击时使用注销,以便我可以注销我的帐户。如何退出帐户?是否有注销方法?

以下是我使用的一些代码:

   public void Mail(String user, String pass) {
    Properties props = new Properties();
    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.getDefaultInstance(props, new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(FROM_MAILID,PASSWORD);
        }
        });
    try {
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(FROM_MAILID));
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(TO_MAILID));
        message.setSubject("Testing Subject");     
        Multipart multipart = new MimeMultipart();     
        MimeBodyPart messageBodyPart = new MimeBodyPart();
        DataSource source = new FileDataSource(new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/wallpaper.jpg"));
        messageBodyPart.setDataHandler(new DataHandler(source));
        messageBodyPart.setFileName("image.png");
        messageBodyPart.setDisposition(MimeBodyPart.ATTACHMENT);
        messageBodyPart.setHeader("Content-ID","<vogue>");
        multipart.addBodyPart(messageBodyPart);
        message.setContent(multipart);
        Transport.send(message);

        Log.d("sent","mail sent...");
    }catch(AuthenticationFailedException afe){
        Log.d("wrong","wrong passwrd....");
    }catch(AddressException ae){


    }catch (MessagingException e) {
        throw new RuntimeException(e);
    }

}

2 个答案:

答案 0 :(得分:0)

使用session.close():在最后一个catch语句后添加finally块:

} finally {
    session.close();
}

答案 1 :(得分:0)

首先,你已经制作了一堆common JavaMail mistakes;清理它们。

没有必要“注销”,因为您只是“登录”了发送邮件所需的时间。当Transport.send完成时,连接将关闭并且您已注销。

相关问题