Tag: javamail

javamail将gmail消息标记为已读

注意:回答后添加:谢谢..是的,我曾尝试过Flag.SEEN为true和saveChanges ..我也读过了读取的getContent标记。 我尝试在循环消息的for语句中使用它。 但是我在下一个循环中再次从文件夹中获取了消息。 我假设文件夹是实时的,所以抓住内容,然后从filter的文件夹中再次抓取消息,以便没有看到应该工作,但我仍然得到相同的消息。 我可以尝试关闭文件夹并重新打开作为测试,以查看它是否已标记。 此外,如果我转到我的客户端并单击该消息,那么我的代码即使在循环中也会停止查看它,所以我希望在代码中也这样做。 original:我正在使用javamail从gmail帐户获取电子邮件,它工作得很好,当我收到消息时我想将其标记为已阅读,是否有人可以给我一些指示? 这是我目前的代码: Properties props = System.getProperties(); props.setProperty(“mail.store.protocol”, “imaps”); try { Session session = Session.getDefaultInstance(props, null); Store store = session.getStore(“imaps”); store.connect(“imap.gmail.com”, eUserName, ePassWord); // Get folder Folder folder = store.getFolder(“INBOX”); if (folder == null || !folder.exists()) { return null; } folder.open(Folder.READ_ONLY); // Only pull unread FlagTerm ft = new […]

如何从邮件中删除用户标志?

我使用JavaMail-1.5将Gmail帐户的IMAP消息附加到Yahoo帐户。 我的要求是从邮件中删除用户标志,因为它们在将邮件附加到其他文件夹时产生错误。 我想从邮件中删除所有用户标志? 下面是获取标志的代码。 Flags flags = message.getFlags(); Flag[] systemFlag = flags.getSystemFlags(); String[] userFlag = flags.getUserFlags(); 请建议如何从我的消息中删除userFlag 。 谢谢

使用gmail smtp服务器和javamail在java中发送无需身份validation的电子邮件

我使用Javamail api和gmail smtp服务器在java中发送邮件而不提供密码。 我使用下面的代码。 这里我使用的是javax.mail jar文件 Properties props= new Properties(); props.put(“mail.smtp.host”, “smtp.gmail.com”); props.put(“mail.smtp.port”, 587); props.put(“mail.transport.protocal”, “smtps”); //Put below to false, if no https is needed props.put(“mail.smtp.STARTTLS.enable”, “false”); props.put(“mail.smtp.auth”, “false”); Session session = Session.getInstance(props); 我收到以下错误 Must issue a STARTTLS command first. b4sm3005855pdh.2 – gsmtp 实现代码有什么问题吗? 是否可以在没有密码的情况下实施? 请任何人帮助我

通过localhost上的Java EE读取电子邮件Outlook

我创建了一个包含3个虚拟机的应用程序,并使用Nagios监控所有这些计算机。 我使用nagios通过postfix将我的电子邮件发送到我的Outlook on localhost,然后我获得了所有带有Java EE应用程序的邮件,并将它们放入我的数据库中。 如何使用Java EE从MS Outlook中提取所有电子邮件并将其放入我的数据库? 我在postfix中使用IMAP将电子邮件发送到我的localhost上的Outlook 我有Outlook版本2007和Windows 7 Cordialement

使用Gmail发送电子邮件时出错

我有以下代码: Email email = new SimpleEmail(); email.setHostName(“smtp.googlemail.com”); email.setSmtpPort(465); email.setAuthenticator(new DefaultAuthenticator(“ruth.sistem@gmail.com”, “XXXXXX”)); email.setSSLOnConnect(true); email.setFrom(“ruth.sistem@gmail.com”); email.setSubject(“TestMail”); email.setMsg(“This is a test mail … :-)”); email.addTo(“ruth.sistem@gmail.com”); email.send(); 我无法连接到gmail,连接出现错误突发,但是所有连接信息都是正确的,不知道什么阻止了我的代码发送电子邮件的连接,我不能发送简单的电子邮件而且我没有丝毫想法这是什么。 org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.googlemail.com:465 at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410) at org.apache.commons.mail.Email.send(Email.java:1437) at com.observatorioLegislativo.util.EmailTeste.enviaEmailSimples(EmailTeste.java:27) at com.observatorioLegislativo.util.EmailTeste.(EmailTeste.java:13) at com.observatorioLegislativo.bean.Teste.main(Teste.java:41) Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.googlemail.com, […]

使用JavaMail连接到IMAP获取“A1 NO LOGIN failed”exception

以下是我正在尝试连接的服务器的详细信息 mailbox_password = KexDa3P7hEtru mailbox_domain = mail.lenderlive.com mailbox_host= corp.lcl mailbox_username = SecondaryQC@lenderlive.com server_type = imap port = 143 我正在使用以下java代码连接到exchange: String domain = “mail.lenderlive.com”; String user= “SecondaryQC@lenderlive.com”; String password= “KexDa3P7hEtru”; String serverType = “imap”; Store store = null; Properties properties = System.getProperties(); Session session = Session.getDefaultInstance(properties); session.setDebug(true); store = session.getStore(serverType); store.connect(domain, user, password); 这是我得到的服务器跟踪: 2016-11-02 15:01:22,885 […]

使用javamail发送邮件和嵌入式图像

我想发送邮件和嵌入式图像。 为此,我使用了以下代码。 它不是完整的代码。 它是代码的一部分 Multipart multipart = new MimeMultipart(“related”); // Create the message part BodyPart messageBodyPart; messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(msgBody); // msgbody contains the contents of the html file messageBodyPart.setHeader(“Content-Type”, “text/html”); multipart.addBodyPart(messageBodyPart); //add file attachments DataSource source; File file = new File(“D:/sample.jpeg”); if(file.exists()){ // add attachment messageBodyPart = new MimeBodyPart(); source = new FileDataSource(file); […]

JavaMail API和Tomcat 7实现

有几个Java EE API就是这样–API(接口,域对象,枚举等,但没有实际的类可以做东西)。 像JPA,JDBC或JTA这样的API。 然后,这些API必须具有实现; 对于JPA,有像Hibernate,MyBatis或TopLink这样的人。 对于JDBC,每个特定的RDBMS都有驱动程序。 对于JTA,有Bitronix和Atomikos。 但是JavaMail呢? 它只是一个API吗? 如果是这样,它的常见实现是什么? 如果我将我的Java应用程序(作为WAR)部署到Tomcat 7,那么这个实现来自哪里(具体而言)? Tomcat是否有自己的JavaMail impl? 什么JAR /包/类构成Tomcat impl?

通过Java应用程序中的amazon服务器上的JavaMail API发送带附件的邮件时出现空指针exception

使用javamail API在亚马逊服务器上发送带有pdf附件的邮件时,它会在日志中抛出空指针exception。 但是同样的代码在本地工作。 public void sendMail(final String mailTo, final String mailSubject, final String mailText, final String filePath, final String fileName) { logger.info(“Inside sendMail Method…”); final Properties config = createConfiguration(); // Creates a mail session. We need to supply username and password for Gmail authentication. final Session session = Session.getInstance(config, new Authenticator() { @Override protected PasswordAuthentication […]

java邮件Base64编码字符串到图像附件

我有一个base64编码的字符串,使用JSON发布到Spring表单中。 data:image/png;base64,iVBORw0KGg……etc 我想将此图像添加为电子邮件的附件。 附加文件工作正常,但它只是添加base64字符串作为附件。 我使用以下代码来创建附件部分。 private MimeBodyPart addAttachment(final String fileName, final String fileContent) throws MessagingException { if (fileName == null || fileContent == null) { return null; } LOG.debug(“addAttachment()”); MimeBodyPart filePart = new MimeBodyPart(); String data = fileContent; DataSource ds; ds = new ByteArrayDataSource(data.getBytes(), “image/*”); // “image/*” filePart.setDataHandler(new DataHandler(ds)); filePart.setFileName(fileName); LOG.debug(“addAttachment success !”); return filePart; […]