Я создал свой Java-класс Selenium. Он отправляет отчет Excel по электронной почте и выдает ошибку как исключение в потоке "main" java.lang.Error: Неразрешенная проблема компиляции: smtpHost не может быть разрешен в переменной
package com.rasvek.SendReportToEmail;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import org.apache.commons.net.smtp.SMTP;
public class SendMailSSLWithAttachment
{
public static void main(String[] args) throws MessagingException
{
//create object of property file
Properties props= new Properties();
props.put("mail.smtp.host" , "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocktFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
///This will handle the complete authentication
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
String username = "username";
String password = "password";
if ((username != null) && (username.length() > 0) && (password != null)
&& (password.length () > 0)) {
return new PasswordAuthentication(username, password);
}
return null;
}
});
try {
//create object of mimeMessage class
Message message = new MimeMessage(session);
//set the From address
message.setFrom(new InternetAddress("username"));
//set the recipient address
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("username"));
//Add the subject Link
message.setSubject("Testing Subject");
//Create object to add multimedia type content
BodyPart messageBodyPart1 = new MimeBodyPart();
//set the body of email
messageBodyPart1.setText("This is Message Body");
//create another object to add another content
MimeBodyPart messageBodyPart2 = new MimeBodyPart();
//Mention the file which you want to send
String fileName = "G:\\a.xlsx";
//create data source and pass the file name
DataSource source = new FileDataSource(fileName);
//set the handler
messageBodyPart2.setDataHandler(new DataHandler(source));
//set the file
messageBodyPart2.setFileName(fileName);
//create Object of MimeMultiPart class
Multipart multipart = new MimeMultipart();
//add body part 1
multipart.addBodyPart(messageBodyPart2);
//add body part 2
multipart.addBodyPart(messageBodyPart1);
//set the content
message.setContent(multipart);
Transport transport=session.getTransport("smtp");
transport.connect(smtpHost, 465, "username", "password");
//finally send the email
Transport.send(message);
System.out.println("================Email Sent==================");
} catch (Exception e)
{
e.printStackTrace();
}
}
}
Я создал свой первый Java-класс Selenium для отправки отчета Excel из моего электронного письма на другой электронный адрес .. Ошибка, отображаемая в транспортном классе, тогда как, transport.send (message);и Исключение в потоке "main" java.lang.Error: Неразрешенная проблема компиляции: smtpHost не может быть разрешен для переменной.пожалуйста, помогите мне в коде