Tag: apache commons email

使用Commons-Email向Gmail发送电子邮件

Email email = new SimpleEmail(); String authuser = “……@gmail.com”; String authpwd = “*******”; // Very Important, Don’t use email.setAuthentication() email.setSmtpPort(465); email.setAuthenticator(new DefaultAuthenticator(authuser, authpwd)); email.setDebug(true); // true if you want to debug email.setHostName(“smtp.gmail.com”); email.getMailSession().getProperties().put(“mail.smtp.auth”, “true”); email.getMailSession().getProperties().put(“mail.debug”, “true”); email.getMailSession().getProperties().put(“mail.smtp.port”, “465”); email.getMailSession().getProperties().put(“mail.smtp.socketFactory.port”, “465”); email.getMailSession().getProperties().put(“mail.smtp.socketFactory.class”, “javax.net.ssl.SSLSocketFactory”); email.getMailSession().getProperties().put(“mail.smtp.socketFactory.fallback”, “false”); email.getMailSession().getProperties().put(“mail.smtp.starttls.enable”, “true”); email.setFrom(“……..@gmail.com”, “SenderName”); email.setSubject(“TestMail”); email.setMsg(“This is a test mail?”); email.addTo(“………….@gmail.com”, […]

使用Apache Commons电子邮件库以Javaforms发送电子邮件

我正在使用Apache Commons电子邮件库发送电子邮件,但我无法通过GMail SMTP服务器发送它们。 任何人都可以提供与GMail SMTP服务器和其他服务器兼容的示例代码吗? 我使用以下代码不起作用: String[] recipients = {“receiver@gmail.com”}; SimpleEmail email = new SimpleEmail(); email.setHostName(“smtp.gmail.com”); email.setAuthentication(“sender@gmail.com”, “mypasswd”); email.setDebug(true); email.setSmtpPort(465); for (int i = 0; i < recipients.length; i++) { email.addTo(recipients[i]); } email.setFrom("sender@gmail.com", "Me"); email.setSubject("Test message"); email.setMsg("This is a simple test of commons-email"); email.send();

使用commons-email-1.3发送电子邮件时出错

在发送电子邮件时,我使用commons-email-1.3收到以下错误。 我已经下载并添加了外部jar到项目中。 请帮我解决这个问题! package mypkg; import org.apache.commons.mail.DefaultAuthenticator; import org.apache.commons.mail.Email; import org.apache.commons.mail.SimpleEmail; public class sendingmail { public static void main(String[] args) throws Exception { Email email = new SimpleEmail(); email.setSmtpPort(587); email.setAuthenticator(new DefaultAuthenticator(“myid”,”mypwd”)); //Here is the error email.setDebug(false); email.setHostName(“smtp.gmail.com”); email.setFrom(“me@gmail.com”); email.setSubject(“Hi”); email.setMsg(“This is a test mail … :-)”); email.addTo(“you@gmail.com”); email.setTLS(true); email.send(); System.out.println(“Mail sent!”); } } 给出错误的行是 email.setAuthenticator(new […]

Apache Commons Email with attach with base64

我正在尝试通过apache.commons.mail发送一个base64编码的文件,我只是无法找到它应该去的Content-Transfer-Encoding: base64标头。 // Create the email MultiPartEmail email = new MultiPartEmail(); email.setSmtpPort(587); email.setDebug(false); email.setHostName(“smtp.gmail.com”); email.setAuthentication(“from@gmail.com”, “password”); email.setTLS(true); email.addTo(“to@example.com”); email.setFrom(“from@example.com”); email.setSubject(“subject”); email.attach(new ByteArrayDataSource( Base64.encodeBase64(attachFull.getBytes()), “text/plain”), “samplefile.txt”, “sample file desc”, EmailAttachment.ATTACHMENT ); 而这正是收件人所获得的。 ——=_Part_0_614021571.1334210788719 Content-Type: text/plain; charset=Cp1252; name=texto.txt Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=samplefile.txt Content-Description: sample file desc 我如何指定该文件是Base64编码?

如何在一个会话中发送多封电子邮件?

我想向不同的收件人发送数千封不同的电子邮件,并希望打开与我的SMTP的连接并保留它。 我希望这更快,然后重新打开ervy邮件的连接。 我想使用Apache Commons Email,但如果有必要,可以回退到Java Mail API。 现在我正在这样做,每次打开关闭连接: HtmlEmail email = new HtmlEmail(); email.setHostName(server.getHostName()); email.setSmtpPort(server.getPort()); email.setAuthenticator(new DefaultAuthenticator(server.getUsername(), server.getPassword())); email.setTLS(true); email.setFrom(“test@example.com”); email.addTo(to); email.setSubject(subject); email.setHtmlMsg(htmlMsg); email.send();