Empezando con el envio automatico de mails

parent 10e982ec
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -47,6 +47,12 @@ ...@@ -47,6 +47,12 @@
<version>42.3.5</version> <version>42.3.5</version>
</dependency> </dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package com.roshka.proyectofinal;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.swing.*;
public class SendMail {
public SendMail()
{
}
public void meetingMail(String postulanteCorreoDestino) throws AddressException, MessagingException {
// emanuel.lugo01@gmail.com
String correo = "nahuelmereles1@gmail.com";
String contra = "ozydnpynyoqsowjn";
String correoDestino = postulanteCorreoDestino;
Properties properties = new Properties();
properties.put("mail.smtp.host","smtp.gmail.com");
properties.setProperty("mail.smtp.starttls.enable","true");
properties.put("mail.smtp.ssl.trust","smtp.gmail.com");
properties.setProperty("mail.smtp.port","587");
properties.setProperty("mail.smtp,user",correo);
properties.setProperty("mail.smtp.auth","true");
Session s = Session.getDefaultInstance(properties);
MimeMessage mensaje = new MimeMessage(s);
mensaje.setFrom(new InternetAddress(correo));
mensaje.addRecipient(Message.RecipientType.TO, new InternetAddress(correoDestino));
mensaje.setSubject("Hola que tal soy yo");
mensaje.setText("Ya funciona?");
Transport transport = s.getTransport("smtp");
transport.connect(correo, contra);
transport.sendMessage(mensaje,mensaje.getAllRecipients());
transport.close();
JOptionPane.showMessageDialog(null, "Mensaje enviado");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment