小编Bra*_*ert的帖子

通过GMailSender发送带附件的电子邮件?

我一直在阅读博客并尝试了大量的实现,但仍未能将图像附加到我通过GMail使用java发送的电子邮件中.我下载了所有的罐子并添加了GMailSender.java,GMailAuthenticator.java和JSSEProvider.java,我能够定期发送常规电子邮件.我尝试过的方式如下所示,中间部分被注释为我希望添加图像的部分.下面是我尝试执行此操作时logcat上的输出.当然,我错过了一些非常简单的事情.有人能指出我吗?提前致谢.

    public synchronized void sendMail(String subject, String body, String sender, String recipients) throws Exception {  
        try {  
            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());  
        MimeMessage message = new MimeMessage(session);  
        DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));  
        message.setSender(new InternetAddress(sender));  
        message.setSubject(subject);  
        message.setDataHandler(handler);  

        /*  
        // Create your new message part  
        BodyPart imgPart = new MimeBodyPart();  

        // Create a related multi-part to combine the parts  
        MimeMultipart multipart = new MimeMultipart("related");  
        multipart.addBodyPart(imgPart);

        String fileName = "http://.../sampleBarcode.png";  

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();  
        if (classLoader == null) {  
                classLoader = this.getClass().getClassLoader();  
            if (classLoader == …
Run Code Online (Sandbox Code Playgroud)

gmail android attachment javax.mail

10
推荐指数
1
解决办法
5205
查看次数

为什么"日期d =新日期();" 返回错误?

这可能已被问及并回答了一百万次,但我似乎无法在任何地方找到解决方案.在Android应用程序中启动活动后,我想显示当前的日期和时间.根据我的理解日期部分可以简单地使用以下内容:

Date d = new Date();  
d.getTime();  
CharSequence s  = DateFormat.format("EEEE, MMMM d, yyyy", d.getTime());  

TextView date = (TextView)findViewById(R.id.dateText);  
date.setText(s);  

TextView time = (TextView)findViewById(R.id.timeText);  
time.setText(s);  
Run Code Online (Sandbox Code Playgroud)

在eclipse中它给了我一个错误,并说构造函数日期是未定义的.我选择了自动修复选项,并在Date构造函数中添加了0作为参数.这产生了一个日期,但日期是1969年12月31日.我在这里错过了什么?

这可能是微不足道的,但我仍然对这些东西不熟悉.

提前感谢任何建议.

time android date

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×2

attachment ×1

date ×1

gmail ×1

javax.mail ×1

time ×1