當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleEmail.setFrom方法代碼示例

本文整理匯總了Java中org.apache.commons.mail.SimpleEmail.setFrom方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleEmail.setFrom方法的具體用法?Java SimpleEmail.setFrom怎麽用?Java SimpleEmail.setFrom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.mail.SimpleEmail的用法示例。


在下文中一共展示了SimpleEmail.setFrom方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendSimpleEmail

import org.apache.commons.mail.SimpleEmail; //導入方法依賴的package包/類
public void sendSimpleEmail(String email_to, String subject, String msg) {
    SimpleEmail email = new SimpleEmail();
    try {
        email.setDebug(debug);
        email.setHostName(smtp);
        email.addTo(email_to);
        email.setFrom(email_from);
        email.setAuthentication(email_from, email_password);
        email.setSubject(subject);
        email.setMsg(msg);
        email.setSSL(ssl);
        email.setTLS(tls);
        email.send();
    } catch (EmailException e) {
        System.out.println(e.getMessage());
    }
}
 
開發者ID:tiagorlampert,項目名稱:sAINT,代碼行數:18,代碼來源:SendEmail.java

示例2: envia

import org.apache.commons.mail.SimpleEmail; //導入方法依賴的package包/類
public static void envia(Registrar reg) {
    try {
        SimpleEmail email = new SimpleEmail();
        email.setHostName("10.1.8.102");
        email.addTo("[email protected]");
        //email.addCc("[email protected]");
        email.addCc("[email protected]");
        email.addCc("[email protected]");
        email.addCc("[email protected]");
        //email.addCc("[email protected]");
        //email.addCc("[email protected]");
        email.setFrom("[email protected]");
        email.setSubject("Error en tablealias");
        String msg = String.format("%nServidor %s, pathInfo %s%nParametros %s ",reg.getNomServidor(), reg.getPagAccesa(), reg.getParametros());
        email.setMsg("Categoria: " + reg.getCategoria() + " , Descripcion " + reg.getDescripcion() + msg + " \n Navegador:" + reg.getExplorador());
        email.send();
        
    } catch (EmailException ex1) {
        ex1.printStackTrace();
    }   
        
}
 
開發者ID:MxSIG,項目名稱:TableAliasV60,代碼行數:23,代碼來源:Correo.java

示例3: sendText

import org.apache.commons.mail.SimpleEmail; //導入方法依賴的package包/類
@Override
public boolean sendText(String to, String subject, String content) throws EmailException {
	SimpleEmail email = new SimpleEmail();
	email.setHostName(host);// 設置使用發電子郵件的郵件服務器
	email.addTo(to);
	email.setAuthentication(user, password);
	email.setFrom(from);
	email.setSubject(subject);
	email.setMsg(content);
	if (port == 465) {
		email.setSSLOnConnect(true);
		email.setSslSmtpPort(Integer.toString(port)); // 若啟用,設置smtp協議的SSL端口號
	}
	else {
		email.setSmtpPort(port);
	}
	email.send();
	return true;
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:20,代碼來源:MailClientImpl.java

示例4: sendSimpleEmail

import org.apache.commons.mail.SimpleEmail; //導入方法依賴的package包/類
/**
 * Test sending an {@link SimpleEmail} rather than a {@link SmtpMessage}.
 */
@Test
public void sendSimpleEmail() throws Exception {
    assertThat(this.sslMailServer.getReceivedMessages().length, is(0));

    SimpleEmail email = new SimpleEmail();
    email.setFrom("[email protected]");
    email.setSubject("subject");
    email.setMsg("content");
    email.addTo("[email protected]");
    email.setSentDate(UtcTime.now().toDate());
    SmtpSender sender = new SmtpSender(email, new SmtpClientConfig("localhost", SMTP_SSL_PORT,
            new SmtpClientAuthentication(USERNAME, PASSWORD), true));
    sender.call();

    // check mailbox after sending
    MimeMessage[] receivedMessages = this.sslMailServer.getReceivedMessages();
    assertThat(receivedMessages.length, is(1));
    assertThat(receivedMessages[0].getSubject(), is("subject"));
    assertThat(receivedMessages[0].getSentDate(), is(FrozenTime.now().toDate()));
    Object expectedContent = "content";
    assertThat(GreenMailUtil.getBody(receivedMessages[0]).trim(), is(expectedContent));
}
 
開發者ID:elastisys,項目名稱:scale.commons,代碼行數:26,代碼來源:TestSmtpSender.java

示例5: sendNormalEmail

import org.apache.commons.mail.SimpleEmail; //導入方法依賴的package包/類
/**
 * Send a verification email to the user's email account if exist.
 * 
 * @param user
 */
public void sendNormalEmail(String subject, String content, String[] addresses ) {
	if ( StringUtil.checkNotEmpty(subject) && StringUtil.checkNotEmpty(content) ) {
		try {
			String emailSmtp = GameDataManager.getInstance().getGameDataAsString(GameDataKey.EMAIL_SMTP, "mail.xinqihd.com");
			SimpleEmail email = new SimpleEmail();
			email.setHostName(emailSmtp);
			email.setAuthenticator(new DefaultAuthenticator(EMAIL_FROM, "[email protected]"));
			email.setFrom(EMAIL_FROM);
			email.setSubject(subject);
			email.setMsg(content);
			email.setCharset("GBK");
			for ( String address : addresses) {
				if ( StringUtil.checkNotEmpty(address) ) {
					email.addTo(address);
				}
			}
			email.send();
		} catch (EmailException e) {
			logger.debug("Failed to send normal email", e);
		}
	}
}
 
開發者ID:wangqi,項目名稱:gameserver,代碼行數:28,代碼來源:EmailManager.java

示例6: enviaEmailSimples

import org.apache.commons.mail.SimpleEmail; //導入方法依賴的package包/類
/**
 * envia email simples (smente texto)
 * Nome remetente, e-mail remetente, nome destinatario, e-mail destinatario,
 * assunto, mensagem
 * @param nomeRemetente
 * @param nomeDestinatario
 * @param emailRemetente
 * @param emailDestinatario
 * @param assunto
 * @param mensagem
 * @throws EmailException
 */
public void enviaEmailSimples(String nomeRementente, String emailRemetente,
        String nomeDestinatario, String emailDestinatario,
        String assunto, StringBuilder mensagem) throws EmailException {

    SimpleEmail email = new SimpleEmail();
    email.setHostName("smtp.hslife.com.br"); // o servidor SMTP para envio do e-mail
    email.addTo(emailDestinatario, nomeDestinatario); //destinatário
    email.setFrom(emailRemetente, nomeRementente); // remetente
    email.setSubject(assunto); // assunto do e-mail
    email.setMsg(mensagem.toString()); //conteudo do e-mail
    email.setAuthentication("[email protected]", "real123");
    //email.setSmtpPort(465);
    //email.setSSL(true);
    //email.setTLS(true);
    email.send();
}
 
開發者ID:herculeshssj,項目名稱:imobiliariaweb,代碼行數:29,代碼來源:EmailService.java

示例7: sendEmail

import org.apache.commons.mail.SimpleEmail; //導入方法依賴的package包/類
public static void sendEmail(String emailAddr, String verifyCode) {
	
	SimpleEmail email = new SimpleEmail();
	email.setHostName("smtp.163.com");
	email.setAuthentication("[email protected]", "xingji19890326");
	email.setCharset("UTF-8");
	try{
		email.addTo(emailAddr);
		email.setFrom("[email protected]");
		email.setSubject("Actsocial dashborad Check");
		email.setMsg(verifyCode);
		email.send();
	}catch(EmailException e){
		e.printStackTrace();
	}
}
 
開發者ID:yancykim,項目名稱:support,代碼行數:17,代碼來源:ValidatorTool.java

示例8: sendEmail

import org.apache.commons.mail.SimpleEmail; //導入方法依賴的package包/類
public static void sendEmail(String emailAddr, String verifyCode) {
	
	SimpleEmail email = new SimpleEmail();
	email.setHostName("smtp.gmail.com");
	email.setAuthentication("[email protected]", "xingji19890326");
	email.setCharset("UTF-8");
	try{
		email.addTo(emailAddr);
		email.setFrom("[email protected]");
		email.setSubject("Actsocial dashborad Check");
		email.setMsg(verifyCode);
		email.send();
	}catch(EmailException e){
		e.printStackTrace();
	}
}
 
開發者ID:yancykim,項目名稱:support,代碼行數:17,代碼來源:EmailUtil.java

示例9: send

import org.apache.commons.mail.SimpleEmail; //導入方法依賴的package包/類
public void send(EmailRequest request) throws EmailException, MalformedURLException {

		SimpleEmail email = new SimpleEmail();
		email.setFrom(request.getFromEmail(), request.getFromName());
		email.setSubject(request.getSubject());
		// Split multiple email addresses on either comma or semicolon
		String[] toAddresses = request.getToEmail().split(",|;");
		for (String thisToAddress : toAddresses) {
			email.addTo(thisToAddress);
		}
		email.setMsg(request.getTextBody());

		// Send email to multiple recipients even if one email address is invalid.
		email.setSendPartial(true);

		addStandardDetails(email);
		email.send();
	}
 
開發者ID:IHTSDO,項目名稱:snomed-release-service,代碼行數:19,代碼來源:EmailSender.java

示例10: conectaEmail

import org.apache.commons.mail.SimpleEmail; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public static org.apache.commons.mail.Email conectaEmail()
		throws EmailException {
	SimpleEmail email = new SimpleEmail();
	email.setHostName(HOSTNAME);
	email.setSmtpPort(465);
	email.setAuthenticator(new DefaultAuthenticator(USERNAME, PASSWORD));
	email.setTLS(true);
	
	email.setFrom(EMAILORIGEM);
	return email;
}
 
開發者ID:ivonildolopes,項目名稱:GERENCIADOR_EVENTOS,代碼行數:13,代碼來源:EmailUtil.java

示例11: toSimpleEmail

import org.apache.commons.mail.SimpleEmail; //導入方法依賴的package包/類
/**
 * Converts an {@link SmtpMessage} to an {@link SimpleEmail} instance.
 * <p/>
 * Note: that the returned {@link Email} instance need to have additional
 * fields populated (such as server host name) before being sent.
 *
 * @param smtpMessage
 * @return
 * @throws SmtpSenderException
 */
private static SimpleEmail toSimpleEmail(SmtpMessage smtpMessage) throws SmtpSenderException {
    try {
        SimpleEmail email = new SimpleEmail();
        email.setFrom(smtpMessage.getFrom().toString());
        email.setSubject(smtpMessage.getSubject());
        email.setMsg(smtpMessage.getContent());
        email.setTo(smtpMessage.getTo());
        email.setSentDate(smtpMessage.getDateSent().toDate());
        return email;
    } catch (EmailException e) {
        throw new SmtpSenderException(
                String.format("failed to convert SmtpMessage to a SimpleEmail: %s", e.getMessage()), e);
    }
}
 
開發者ID:elastisys,項目名稱:scale.commons,代碼行數:25,代碼來源:SmtpSender.java

示例12: testSimpleEmail

import org.apache.commons.mail.SimpleEmail; //導入方法依賴的package包/類
@Test
public void testSimpleEmail()
    throws EmailException, MessagingException
{
    Smtp smtp = WERVAL.application().plugin( Smtp.class );
    assertThat( smtp, notNullValue() );

    SimpleEmail email = smtp.newSimpleEmail();
    email.setFrom( "[email protected]" );
    email.addTo( "[email protected]" );
    email.setSubject( "Simple Email" );
    email.send();

    List<WiserMessage> messages = wiser.getMessages();
    assertThat( messages.size(), is( 1 ) );
    WiserMessage message = messages.get( 0 );
    assertThat( message.getMimeMessage().getHeader( "From" )[0], equalTo( "[email protected]" ) );
    assertThat( message.getMimeMessage().getHeader( "To" )[0], equalTo( "[email protected]" ) );
    assertThat( message.getMimeMessage().getHeader( "Subject" )[0], equalTo( "Simple Email" ) );

    MetricRegistry metrics = WERVAL.application().plugin( Metrics.class ).metrics();
    assertThat( metrics.meter( "io.werval.modules.smtp.sent" ).getCount(), is( 1L ) );
    assertThat( metrics.meter( "io.werval.modules.smtp.errors" ).getCount(), is( 0L ) );

    HealthCheckRegistry healthChecks = WERVAL.application().plugin( Metrics.class ).healthChecks();
    assertTrue( healthChecks.runHealthCheck( "smtp" ).isHealthy() );
}
 
開發者ID:werval,項目名稱:werval,代碼行數:28,代碼來源:SmtpPluginTest.java

示例13: initialize

import org.apache.commons.mail.SimpleEmail; //導入方法依賴的package包/類
public boolean initialize ( ) {
	TreeMap < String , String > params = getVirtualSensorConfiguration( ).getMainClassInitialParams( );

	if(params.get(INITPARAM_SUBJECT) != null) subject = params.get(INITPARAM_SUBJECT);
	if(params.get(INITPARAM_RECEIVER) != null) receiverEmail = params.get(INITPARAM_RECEIVER);
	if(params.get(INITPARAM_SENDER) != null) senderEmail = params.get(INITPARAM_SENDER);
	else {
		logger.error( "The parameter *" + INITPARAM_SENDER + "* is missing from the virtual sensor processing class's initialization." );
		logger.error( "Loading the virtual sensor failed" );
		return false;
	}
	if(params.get(INITPARAM_SERVER) != null) mailServer = params.get(INITPARAM_SERVER);
	else {
		logger.error( "The parameter *" + INITPARAM_SERVER + "* is missing from the virtual sensor processing class's initialization." );
		logger.error( "Loading the virtual sensor failed" );
		return false;
	}
	
	try {
		email = new SimpleEmail();
		email.setHostName(mailServer);
		email.setFrom(senderEmail);
		email.setSubject( subject );
	} catch(Exception e) {
		logger.error( "Email initialization failed", e );
		return false;
	}
	return true;
}
 
開發者ID:LSIR,項目名稱:gsn,代碼行數:30,代碼來源:EmailVirtualSensor.java

示例14: send

import org.apache.commons.mail.SimpleEmail; //導入方法依賴的package包/類
public static void send(String recepient, String subject, String message) throws EmailException, ConfigurationException {
	SimpleEmail email = new SimpleEmail();
	Configurable config = Configuration.getInstance();
	email.setHostName(config.getStringValue("profile.smtp.host"));
	email.setSmtpPort(config.getIntValue("profile.smtp.port"));
	email.setAuthenticator(new DefaultAuthenticator(config.getStringValue("profile.username"), config.getStringValue("profile.password")));
	email.setSSLOnConnect(true);
	email.setFrom(config.getStringValue("profile.email"), config.getStringValue("profile.name"));
	email.addTo(recepient);
	email.setSubject(subject);
	email.setMsg(message);
	email.send();
}
 
開發者ID:IvanTrendafilov,項目名稱:notifier-app,代碼行數:14,代碼來源:EmailSender.java

示例15: doGet

import org.apache.commons.mail.SimpleEmail; //導入方法依賴的package包/類
/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
 *      response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	String trocaform = request.getParameter("trocaform");
	if (trocaform != null) {
		StringBuilder sb = new StringBuilder();
		sb.append(
				"<form role='form' class='form-group' id='formrecupera' action='/EstacionamentoWeb/recuperar' method='post' >");
		sb.append("<label>Login: </label>");
		sb.append("<input class='form-control' type='text' name='login' size='20' required='required'><br>");
		sb.append("<label>Email: </label>");
		sb.append("<input class='form-control' type='email' size='30' name='email' required='required'><br>");
		sb.append("<input class='btn btn-default' type='submit' value='Recuperar'>");
		sb.append("</form>");

		response.getWriter().write(sb.toString());
		response.setStatus(200);
	} else {
		String login = request.getParameter("login");
		String email = request.getParameter("email");

		UsuarioBean usuario = new UsuarioBean();
		usuario = UsuarioDao.getUsuario(login);

		String scheme = request.getScheme();
		String serverName = request.getServerName();
		int serverPort = request.getServerPort();
		String contextPath = request.getContextPath();
		String resultpath = scheme + "://" + serverName + ":" + serverPort + contextPath;

		Random gerador = new Random();

		String aleatorio = "";

		for (int i = 1; i < 65; i++) {
			aleatorio += String.valueOf(gerador.nextInt(10));
		}

		usuario.setHashrecuperasenha(UsuarioDao.geraHashCriptografada(aleatorio));
		UsuarioDao.insereHashRecuperaSenha(usuario);

		SimpleEmail enviaemail = new SimpleEmail();

		String status = null;

		if ((usuario.getEmail() != null && usuario.getLogin() != null)
				&& (usuario.getEmail().equals(email) && usuario.getLogin().equals(login))) {
			try {
				enviaemail.setDebug(true);
				enviaemail.setHostName("smtp.gmail.com");
				enviaemail.setSmtpPort(587);
				enviaemail.setAuthentication("Seu Login Aqui", "Sua Senha Aqui");
				enviaemail.setStartTLSEnabled(true);
				enviaemail.addTo(usuario.getEmail());
				enviaemail.setFrom("Seu Email Aqui");
				enviaemail.setSubject("Recuperação de Senha - EstacionamentoWeb");
				enviaemail.setMsg("Para recuperar a sua senha clique no link a seguir: " + resultpath
						+ "/novasenha.jsp?hash=" + usuario.getHashrecuperasenha());
				enviaemail.send();
			} catch (Exception e) {
				System.out.println(e);
			}
			status = "Siga as orientações enviadas por email.";
			response.sendRedirect("/EstacionamentoWeb/login.jsp?alert=info&status=" + status);
		} else {
			status = "Login ou Email inválido!";
			response.sendRedirect("/EstacionamentoWeb/login.jsp?alert=danger&status=" + status);
		}
	}
}
 
開發者ID:rasertux,項目名稱:EstacionamentoWeb,代碼行數:74,代碼來源:RecuperaSenha.java


注:本文中的org.apache.commons.mail.SimpleEmail.setFrom方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。