当前位置: 首页>>代码示例>>Java>>正文


Java MultiPartEmail.setSSLOnConnect方法代码示例

本文整理汇总了Java中org.apache.commons.mail.MultiPartEmail.setSSLOnConnect方法的典型用法代码示例。如果您正苦于以下问题:Java MultiPartEmail.setSSLOnConnect方法的具体用法?Java MultiPartEmail.setSSLOnConnect怎么用?Java MultiPartEmail.setSSLOnConnect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.mail.MultiPartEmail的用法示例。


在下文中一共展示了MultiPartEmail.setSSLOnConnect方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fillEmail

import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
/**
 * Fill email.
 *
 * @param email
 *            the email
 * @throws EmailException
 *             the email exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public void fillEmail(final MultiPartEmail email) throws EmailException, IOException {
	email.setHostName(getHost());
	email.setSmtpPort(getSmtpPort());
	
	email.addTo(getTo());
	email.setFrom(getFrom());
	email.setSubject(getSubject());
	email.setMsg(getMsg());
	email.setSSLOnConnect(isSecured());
	if (isRequiresAuthentication()) {
		email.setAuthentication(getUsername(), getPassword());
	}
	for (int i = 0; i < this.attachements.size(); i++) {
		final Attachment attachment = this.attachements.get(i);
		final ByteArrayDataSource ds = new ByteArrayDataSource(attachment.getData(), attachment.getMimeType());
		email.attach(ds, attachment.getName(), attachment.getDescription());
	}
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:29,代码来源:MailInfo.java

示例2: main

import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    Email email = new SimpleEmail();
    email.setHostName("smtp.googlemail.com");
    email.setSSLOnConnect(false); //OK

    Email email2 = new SimpleEmail();
    email2.setHostName("smtp2.googlemail.com");        
    email2.setSSLOnConnect(true); //BAD
    //email2.setSmtpPort(465);
    //email2.setAuthenticator(new DefaultAuthenticator("username", "password"));
    //email2.setFrom("[email protected]");
    //email2.setSubject("TestMail");
    //email2.setMsg("This is a test mail ... :-)");
    //email2.addTo("[email protected]");
    //email2.send();

    MultiPartEmail emailMulti = new MultiPartEmail();
    emailMulti.setHostName("mail.myserver.com");
    emailMulti.setSSLOnConnect(true); //BAD

    HtmlEmail htmlEmail = new HtmlEmail();
    htmlEmail.setHostName("mail.myserver.com");
    htmlEmail.setSSLOnConnect(true); //BAD

    ImageHtmlEmail imageEmail = new ImageHtmlEmail();
    imageEmail.setHostName("mail.myserver.com");
    imageEmail.setSSLOnConnect(true);
    imageEmail.setSSLCheckServerIdentity(true); //OK
    
    ImageHtmlEmail imageEmail2 = new ImageHtmlEmail();
    imageEmail2.setHostName("mail2.myserver.com");
    imageEmail2.setSSLCheckServerIdentity(true); //OK - reversed order
    imageEmail2.setSSLOnConnect(true);

    ImageHtmlEmail imageEmail3 = new ImageHtmlEmail();
    imageEmail3.setHostName("mail3.myserver.com");
    imageEmail3.setSSLOnConnect(true); //BAD
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:39,代码来源:InsecureSmtpSsl.java

示例3: sendMultipartEmail

import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
private void sendMultipartEmail() throws MangooMailerException {
    Config config = Application.getInstance(Config.class);
    try {
        MultiPartEmail multiPartEmail = new MultiPartEmail();
        multiPartEmail.setCharset(Default.ENCODING.toString());
        multiPartEmail.setHostName(config.getSmtpHost());
        multiPartEmail.setSmtpPort(config.getSmtpPort());
        multiPartEmail.setAuthenticator(getDefaultAuthenticator());
        multiPartEmail.setSSLOnConnect(config.isSmtpSSL());
        multiPartEmail.setFrom(this.from);
        multiPartEmail.setSubject(this.subject);
        multiPartEmail.setMsg(render());
        
        for (String recipient : this.recipients) {
            multiPartEmail.addTo(recipient);
        }
        
        for (String cc : this.ccRecipients) {
            multiPartEmail.addCc(cc);
        }
        
        for (String bcc : this.bccRecipients) {
            multiPartEmail.addBcc(bcc);
        }
        
        for (File file : this.files) {
            multiPartEmail.attach(file);
        }
        
        multiPartEmail.send();
    } catch (EmailException | MangooTemplateEngineException e) {
        throw new MangooMailerException(e);
    }   
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:35,代码来源:Mail.java

示例4: prepareDirectMail

import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
/**
 * Prepares a eMail to be send direct over the mandator smtp configuration.
 * The email is missing: to, subject, message and optional attachments.
 *
 * @return the email
 * @throws EmailException if something is wrong in the subsystem.
 */
public MultiPartEmail prepareDirectMail() throws EmailException {
    MultiPartEmail email = new MultiPartEmail();
    email.setHostName(smtpConfiguration.getHostname());
    email.addBcc(company.getEmail());
    email.setFrom(company.getEmail(), company.getEmailName());
    email.setAuthentication(smtpConfiguration.getSmtpAuthenticationUser(), smtpConfiguration.getSmtpAuthenticationPass());
    email.setStartTLSEnabled(false);
    email.setSSLCheckServerIdentity(false);
    email.setSSLOnConnect(false);
    email.setCharset(smtpConfiguration.getCharset());
    return email;
}
 
开发者ID:gg-net,项目名称:dwoss,代码行数:20,代码来源:Mandator.java

示例5: share

import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
public void share()
{
	MultiPartEmail email = new MultiPartEmail();
	email.setHostName(GMAIL_SMTP_URL);
	email.setSmtpPort(GMAIL_SMTP_PORT);
	// needs gmail pass for from email
	email.setAuthenticator(new DefaultAuthenticator(from, fromPassword));
	email.setSSLOnConnect(true);
	if(imagePath!=null && !imagePath.isEmpty()){
	 EmailAttachment attachment = new EmailAttachment();
	  attachment.setPath(imagePath);
	  attachment.setDisposition(EmailAttachment.ATTACHMENT);
	  attachment.setDescription(ATTACHMENT_DESC);
	  attachment.setName(ATTACHMENT_IMG_TITLE);
	  try {
		email.attach(attachment);
	  } catch (Exception e1) {
		
		e1.printStackTrace();
	  }
	
	}
	
	try{
	email.setFrom(from);
	email.setSubject(EMAIL_SUBJECT);
	email.setMsg(message);
	email.addTo(to);
	email.send();
	}
	catch(Exception e)
	{
		System.out.println(e.toString());
	}
}
 
开发者ID:aarya123,项目名称:DotVinci,代码行数:36,代码来源:GmailShare.java

示例6: sendSupportRequest

import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
public boolean sendSupportRequest() {
        try {
            String senderName = sender_name.getText();
            String senderEmail = sender_email.getText();
            String sendingTime = date_time.getText();
            String systemUser = system_user.getText();

            String message = messge_content.getText();

            if (message.isEmpty()) {
                JOptionPane.showMessageDialog(this, "You haven't entered your message. Please enter the message and try again.");
            }

            // Create the email message
            MultiPartEmail email = new MultiPartEmail();
            email.setHostName("mail.mdcc.lk");
            email.addTo("[email protected]", "Viraj @ MDCC");
            email.addTo("[email protected]", "Isuru @ MDCC");
            email.setFrom(senderEmail, senderName);
            email.setAuthentication("[email protected]", "mdccmail123");
            email.setSSLOnConnect(true);
            email.setStartTLSEnabled(true);
            email.setSmtpPort(465);

//            email.setHostName("mail.mdcc.lk");
//            email.addTo("[email protected]", "Isuru Ranawaka");
//            email.setFrom("[email protected]", "Isuru Ranawaka from MDCC");
//            email.setSubject("Test email with inline image");
//            email.setAuthentication("[email protected]", "=-88isuru");
//            email.setSSLOnConnect(false);
//            email.setSmtpPort(25);
//            email.setDebug(true);
            email.setSubject("New Support Request from Application");

            String textMessage = "Application - Support Request\n"
                    + "---------------------------------------------------------------------\n"
                    + "New Support Request from _P1_\n"
                    + "Sent by _P2_ on _P3_\n"
                    + "---------------------------------------------------------------------\n"
                    + "\n"
                    + "Message: \n_P4_\n"
                    + "\n"
                    + "---------------------------------------------------------------------\n"
                    + "This email was sent from Application. \n"
                    + "Please note that this is an automatically generated email and \n"
                    + "your replies will go nowhere.\n"
                    + "\n"
                    + "© All Rights Reserved - Management Development Co-operative Co. Ltd.";

            textMessage = textMessage.replace("_P1_", systemUser);
            textMessage = textMessage.replace("_P2_", senderName + "(" + senderEmail + ")");
            textMessage = textMessage.replace("_P3_", sendingTime);
            textMessage = textMessage.replace("_P4_", message);

            //attach file
            if (!attachedFile.trim().isEmpty()) {
                email.attach(new File(attachedFile));
            }
            
            // set the alternative message
            email.setMsg(textMessage);

            // send the email
            email.send();
            return true;
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Cannot send email.\nError:" + e.getLocalizedMessage(), "Sending failure", JOptionPane.ERROR_MESSAGE);
            return false;
        }
    }
 
开发者ID:isu3ru,项目名称:java-swing-template,代码行数:71,代码来源:Support.java

示例7: sendEmail

import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
/**
   * Sends an email with a PDF attachment.
   * @throws TransportConfigurationException 
   * @throws EmailException 
   * @throws MessagingException 
   */
  public void sendEmail(String receipient, byte[] pdf) throws TransportConfigurationException, EmailException, MessagingException {
  	if(!configuration.isEnabled()) {
          throw new TransportConfigurationException("Email transport is not enabled in server configuration file!");
      }

      final MultiPartEmail email = new MultiPartEmail();
      email.setCharset(EmailConstants.UTF_8);
      

      if (Strings.isNullOrEmpty(configuration.getHostname())) {
          throw new TransportConfigurationException("No hostname configured for email transport while trying to send alert email!");
      } else {
          email.setHostName(configuration.getHostname());
      }
      email.setSmtpPort(configuration.getPort());
      if (configuration.isUseSsl()) {
          email.setSslSmtpPort(Integer.toString(configuration.getPort()));
      }

      if(configuration.isUseAuth()) {
          email.setAuthenticator(new DefaultAuthenticator(
                  Strings.nullToEmpty(configuration.getUsername()),
                  Strings.nullToEmpty(configuration.getPassword())
          ));
      }

      email.setSSLOnConnect(configuration.isUseSsl());
      email.setStartTLSEnabled(configuration.isUseTls());
      if (pluginConfig != null && !Strings.isNullOrEmpty(pluginConfig.getString("sender"))) {
          email.setFrom(pluginConfig.getString("sender"));
      } else {
          email.setFrom(configuration.getFromEmail());
      }
      
      
      email.setSubject("Graylog Aggregates Report");

      Calendar c = Calendar.getInstance();

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

      email.attach(new ByteArrayDataSource(pdf, "application/pdf"),
      	      "aggregates_report_" + df.format(c.getTime()) +".pdf", "Graylog Aggregates Report",
      	       EmailAttachment.ATTACHMENT);
              
      
      email.setMsg("Please find the report attached.");

      email.addTo(receipient);
              	
     	LOG.debug("sending report to " + email.getToAddresses().toString());
      	
     	email.send();
      
  }
 
开发者ID:cvtienhoven,项目名称:graylog-plugin-aggregates,代码行数:62,代码来源:ReportSender.java


注:本文中的org.apache.commons.mail.MultiPartEmail.setSSLOnConnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。