added bcc

git-svn-id: https://svn.coded.pt/svn/SIPRP@1664 bb69d46d-e84e-40c8-a05a-06db0d633741
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
Diogo Neves 15 years ago
parent 8b6cf8bd2e
commit acb8666ddd

@ -1,31 +1,31 @@
# production # production
server.siprp = localhost
port.siprp = 5436
database.siprp = siprp
username.siprp = postgres
#password.siprp =
server.siprp_local = localhost
port.siprp_local = 5436
database.siprp_local = siprp_local_3
username.siprp_local = postgres
#password.siprp_local =
# tests
#server.siprp = localhost #server.siprp = localhost
#port.siprp = 5432 #port.siprp = 5436
#database.siprp = siprp #database.siprp = siprp
#username.siprp = postgres #username.siprp = postgres
#password.siprp = Typein ##password.siprp =
# #
#server.siprp_local = localhost #server.siprp_local = localhost
#port.siprp_local = 5432 #port.siprp_local = 5436
#database.siprp_local = siprp_local_3 #database.siprp_local = siprp_local_3
#username.siprp_local = postgres #username.siprp_local = postgres
#password.siprp_local = Typein ##password.siprp_local =
# tests
server.siprp = localhost
port.siprp = 5432
database.siprp = siprp
username.siprp = postgres
password.siprp = Typein
server.siprp_local = localhost
port.siprp_local = 5432
database.siprp_local = siprp_local_3
username.siprp_local = postgres
password.siprp_local = Typein
#server.siprp = www.evolute.pt #server.siprp = www.evolute.pt
#port.siprp = 5436 #port.siprp = 5436

@ -1,10 +1,6 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mail; package mail;
import com.evolute.utils.error.ErrorLogger;
import java.util.Date; import java.util.Date;
import java.util.Properties; import java.util.Properties;
import javax.mail.BodyPart; import javax.mail.BodyPart;
@ -17,77 +13,80 @@ import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart; import javax.mail.internet.MimeMultipart;
/** public class Mail
* {
* @author lluis private final static String SMTP_HOST = "mail.evolute.pt";
*/
public class Mail {
private final static String SMTP_HOST = "mail2.evolute.pt";
private final static int SMTP_PORT = 587; private final static int SMTP_PORT = 587;
private final String SMTP_USERNAME = "acidentes.auchan@siprp.pt";
private final String mail_username = "acidentes.auchan@siprp.pt"; private final String SMTP_PASSWORD = "EghRzS2l";
// private final String mail_password = "47Ju6Vb";
private final String mail_password = "EghRzS2l";
public final static String ENDERECO_ENVIO = "planos.auchan@siprp.pt"; public final static String ENDERECO_ENVIO = "planos.auchan@siprp.pt";
//public final static String ENDERECO_ENVIO = "lluis@evolute.pt"; //testes
private final String BCC_1 = "departamentotecnico@siprp.pt";
public void send(String emailTo, String emailFrom, String assunto, String texto_email) throws Exception public void send( String emailTo, String emailFrom, String assunto, String texto_email )
throws Exception
{ {
Properties props = new Properties(); Properties props = new Properties();
//props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", SMTP_HOST ); props.put("mail.smtp.host", SMTP_HOST );
props.put("mail.from", emailFrom ); props.put("mail.from", emailFrom );
props.put("mail.smtp.auth", "true" ); props.put("mail.smtp.auth", "true" );
props.put("mail.smtp.user", mail_username ); props.put("mail.smtp.user", SMTP_USERNAME );
props.put("mail.smtp.password", mail_password ); props.put("mail.smtp.password", SMTP_PASSWORD );
// props.put("mail.smtp.user", "lluis");
// props.put("mail.smtp.password", "654321");
Session session = Session.getInstance( props ); Session session = Session.getDefaultInstance( props );
// Authenticator auth = new SMTPAuthenticator();
// Session session = Session.getDefaultInstance(props, auth);
Message msg = new MimeMessage( session ); Message msg = new MimeMessage( session );
msg.setFrom( new InternetAddress( emailFrom ) ); msg.setFrom( new InternetAddress( emailFrom ) );
InternetAddress[] address = {new InternetAddress( emailTo )}; InternetAddress[] address = new InternetAddress[] {
new InternetAddress( emailTo )
};
msg.setRecipients( Message.RecipientType.TO, address ); msg.setRecipients( Message.RecipientType.TO, address );
((MimeMessage)msg).setSubject(assunto, "UTF-8");
msg.setSentDate(new Date()); InternetAddress[] addressBCC = new InternetAddress[] {
new InternetAddress( BCC_1 )
};
msg.setRecipients( Message.RecipientType.BCC, addressBCC );
( ( MimeMessage ) msg ).setSubject( assunto, "UTF-8" );
msg.setSentDate( new Date() );
Multipart multipart = new MimeMultipart(); Multipart multipart = new MimeMultipart();
BodyPart msgBodyPart = new MimeBodyPart(); BodyPart msgBodyPart = new MimeBodyPart();
String html; String html;
html="<html><head> <meta content='text/html;charset=ISO-8859-1' http-equiv='Content-Type'></head>"; html="<html><head> <meta content='text/html;charset=ISO-8859-1' http-equiv='Content-Type'></head>";
html+="<body bgcolor='#ffffff' text='#000000'>"; html+="<body bgcolor='#ffffff' text='#000000'>";
html+= texto_email; html+= texto_email;
html+="<body></html>"; html+="<body></html>";
msgBodyPart.setContent(html, "text/html"); msgBodyPart.setContent( html, "text/html" );
multipart.addBodyPart(msgBodyPart); multipart.addBodyPart( msgBodyPart );
msg.setContent(multipart); msg.setContent( multipart );
// Transport.send(msg); String log = "Mail . send() :\n" +
Transport t; "To : " + emailTo + ", From : " + emailFrom + "\n" +
t = session.getTransport( "smtp" ); "Subject : " + assunto + "\n" +
"Message Body :\n" + texto_email + "\n" +
t.connect( SMTP_HOST, SMTP_PORT, mail_username, mail_password ); "\n" +
t.sendMessage( msg, msg.getAllRecipients() ); "Result : ";
try
t.close(); {
// System.out.println("Email Enviado !!!! "); Transport t = session.getTransport( "smtp" );
t.connect( SMTP_HOST, SMTP_PORT, SMTP_USERNAME, SMTP_PASSWORD );
} t.sendMessage( msg, msg.getAllRecipients() );
t.close();
// private class SMTPAuthenticator extends Authenticator {
// public PasswordAuthentication getPasswordAuthentication() { log += "sent !\n";
// String username = "lluis"; ErrorLogger.log( log );
// String password = "654321"; }
// return new PasswordAuthentication(username, password); catch ( Exception e )
// } {
// log += "error occurred : " + e.getMessage() + "\n(See next error log (should be this exception stacktrace!)\n";
// } ErrorLogger.log( log );
// note: no need to call log( e ) as it should be caught be who called this method ..
throw e;
}
}
} }

@ -2063,7 +2063,7 @@ public class EditarPlano extends AbstractPageBean
enviarMail( p ); enviarMail( p );
} }
public void enviarMail( PlanoActuacao p ) private void enviarMail( PlanoActuacao p )
{ {
Mail mail = new Mail(); Mail mail = new Mail();
String assunto = ""; String assunto = "";

Loading…
Cancel
Save