Java Code Examples for org.apache.commons.mail.MultiPartEmail#setAuthentication()

The following examples show how to use org.apache.commons.mail.MultiPartEmail#setAuthentication() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: xiaoV   File: MailUtil.java    License: GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public static void sendMail(String content) {
	MailSenderInfo mailInfo = getMailSenderInfo(content);
	MultiPartEmail email = new MultiPartEmail();
	try {
		email.setTLS(mailInfo.isSslenable());
		email.setHostName(mailInfo.getMailServerHost());
		email.setAuthentication(mailInfo.getUserName(),
				mailInfo.getPassword());// 用户名和密码
		email.setFrom(mailInfo.getFromAddress()); // 发送方
		email.addTo(mailInfo.getToAddress());// 接收方
		email.setSubject(mailInfo.getSubject()); // 标题
		email.setCharset("UTF-8");
		email.setMsg(mailInfo.getContent()); // 内容
		email.send();

	} catch (EmailException e) {
		e.printStackTrace();
	}
}
 
Example 2
public void sendEmailAttachment(String email_to, String assunto, String msg, String file_logs) {
    File fileLogs = new File(file_logs);
    EmailAttachment attachmentLogs = new EmailAttachment();
    attachmentLogs.setPath(fileLogs.getPath());
    attachmentLogs.setDisposition(EmailAttachment.ATTACHMENT);
    attachmentLogs.setDescription("Logs");
    attachmentLogs.setName(fileLogs.getName());

    try {
        MultiPartEmail email = new MultiPartEmail();
        email.setDebug(debug);
        email.setHostName(smtp);
        email.addTo(email_to);
        email.setFrom(email_from);
        email.setAuthentication(email_from, email_password);
        email.setSubject(assunto);
        email.setMsg(msg);
        email.setSSL(true);
        email.attach(attachmentLogs);
        email.send();
    } catch (EmailException e) {
        System.out.println(e.getMessage());
    }
}
 
Example 3
Source Project: jpa-invoicer   File: InvoiceFacade.java    License: The Unlicense 6 votes vote down vote up
public void sendInvoice(final Invoice invoice) throws EmailException, IOException {
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writeAsPdf(invoice, out);
        ByteArrayDataSource dataSource =
                new ByteArrayDataSource(out.toByteArray(), "application/pdf");
        String fileName = "invoice_" + invoice.getInvoiceNumber() + ".pdf";

        MultiPartEmail email = new MultiPartEmail();
        email.setAuthentication(smtpUsername, smtpPassword);
        email.setHostName(smtpHostname);
        email.setSmtpPort(smtpPort);
        email.setFrom(smtpFrom);
        email.addTo(invoice.getInvoicer().getEmail());
        email.setSubject(smtpSubject);
        email.setMsg(smtpMessage);
        email.attach(dataSource, fileName, "Invoice");
        email.send();
    }
}
 
Example 4
Source Project: SpyGen   File: SendEmail.java    License: Apache License 2.0 5 votes vote down vote up
public SendEmail(String subject, String msg) {
    try {
        email = new MultiPartEmail();
        email.setDebug(DEBUG);
        email.setHostName(SMTP);
        email.setSSL(SSL);
        email.addTo(Settings.receiverMail);
        email.setFrom(Settings.senderMail);
        email.setAuthentication(Settings.senderMail, Settings.senderPassword);
        email.setSubject(subject);
        email.setMsg(msg);
    } catch(EmailException ee) {
        ee.printStackTrace();
    }
}
 
Example 5
public void sendEmailAttachment(String email_to, String assunto, String msg, String file, String file_logs) {
    File fileScreenshot = new File(file);
    EmailAttachment attachment = new EmailAttachment();
    attachment.setPath(fileScreenshot.getPath());
    attachment.setDisposition(EmailAttachment.ATTACHMENT);
    attachment.setDescription("Attachment");
    attachment.setName(fileScreenshot.getName());

    File fileLogs = new File(file_logs);
    EmailAttachment attachmentLogs = new EmailAttachment();
    attachmentLogs.setPath(fileLogs.getPath());
    attachmentLogs.setDisposition(EmailAttachment.ATTACHMENT);
    attachmentLogs.setDescription("Logs");
    attachmentLogs.setName(fileLogs.getName());

    try {
        MultiPartEmail email = new MultiPartEmail();
        email.setDebug(debug);
        email.setHostName(smtp);
        email.addTo(email_to);
        email.setFrom(email_from);
        email.setAuthentication(email_from, email_password);
        email.setSubject(assunto);
        email.setMsg(msg);
        email.setSSL(true);
        email.attach(attachment);
        email.attach(attachmentLogs);
        email.send();
    } catch (EmailException e) {
        System.out.println(e.getMessage());
    }
}