java:18:错误:找不到符号
接收错误java:18:错误:找不到符号,java,email,Java,Email,接收错误 import java.security.Security; import java.util.Properties; import javax.mail.Message; import javax.mail.NoSuchProviderException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.PasswordAuthentic
import java.security.Security;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.PasswordAuthentication;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMail {
public String to;
public String subject;
public String text;
SendMail(String to, String subject, String text){
this.to = to;
this.subject = subject;
this.text = text;
}
public void send() throws NoSuchProviderException, AddressException{
try
{
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props=new Properties();
props.setProperty("mail.transport.protocol","smtp");
props.setProperty("mail.host","mail.epro-tech.com");
props.put("mail.smtp.auth","true");
props.put("mail.smtp.port","465");
props.put("mail.debug","true");
props.put("mail.smtp.socketFactory.port","465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback","false");
Session session=Session.getDefaultInstance(props,new GJMailAuthenticator());
session.setDebug(true);
Transport transport=session.getTransport();
InternetAddress addressFrom=new InternetAddress("itopstest@epro-tech.com");
MimeMessage message=new MimeMessage(session);
message.setSender(addressFrom);
message.setSubject(subject);
message.setContent(text,"text/html");
InternetAddress addressTo=new InternetAddress(to);
message.setRecipient(Message.RecipientType.TO,addressTo);
transport.connect();
Transport.send(message);
transport.close();
System.out.println("DONE");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
class GJMailAuthenticator extends javax.mail.Authenticator{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("itopstest@epro-tech.com","Ops@890T");
}
}
public class Mail extends SendMail {
public static void main(String[] args) {
String to = "noreply@eprocorp.com";
String subject = "Test";
String message = "A test message";
SendMail SendMail = new SendMail(to, subject, message);
try
{
SendMail.send();
}
catch (Exception e)
{
//
}
}
}
有谁能建议我如何纠正这个问题吗?我知道有问题 邮件类正在扩展没有默认cunstructor的SendMail类。所以,要么在SendMail类中创建一个默认cunstructor,要么在Mail类中创建一个参数化cunstructor SendMail.send;在这里,我猜编译器正在尝试访问SendMail类的静态方法。创建像SendMail SendMail=newsendmailto、subject、message这样的对象;并访问sendMail.send等发送方法 为这两个类指定适当的包名,因为类具有可以在JAR中找到的通用名称
代码已包含构造函数 SendMailString收件人、字符串主题、字符串文本 { 这个; this.subject=主语; this.text=文本; }
缺少SendMail对象。应在Mail中导入SendMail类包Class@user2053430SendMail类包是否已导入???
Mail.java:18: error: cannot find symbol
SendMail SendMail = new SendMail(to, subject, message);
^
symbol: class SendMail
location: class Mail
Mail.java:18: error: cannot find symbol
SendMail SendMail = new SendMail(to, subject, message);
^
symbol: class SendMail
location: class Mail
2 errors
even at extends in the class Mail i can see the errors