通过java发送短信

通过java发送短信,java,sms,Java,Sms,嗨,我正在尝试通过java发送短信,我已经下载了mail.jar并设置为classpath 下面是我的java代码保存的SMTPSend.java和错误plz指南我 import java.util.Date; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; public class SMTPSend { public SMTPSend() { } publi

嗨,我正在尝试通过java发送短信,我已经下载了mail.jar并设置为classpath 下面是我的java代码保存的SMTPSend.java和错误plz指南我

import java.util.Date;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SMTPSend {

    public SMTPSend() {
    }

    public void msgsend() {

        String username = "MySMSUsername";
        String password = "MyPassword";
        String smtphost = "MySMSHost.com";
        String compression = "My SMS Compression Information";
        String from = "mySMSUsername@MySMSHost.com";
        String to = "9762285104";
        String body = "Hello SMS World!";
        Transport myTransport = null;

        try {
            Properties props = System.getProperties();

            props.put("mail.smtp.auth", "true");

            Session mailSession = Session.getDefaultInstance(props, null);

            Message msg = new MimeMessage(mailSession);

            msg.setFrom(new InternetAddress(from));

            InternetAddress[] address = {new InternetAddress(to)};

            msg.setRecipients(Message.RecipientType.TO, address);

            msg.setSubject(compression);

            msg.setText(body);

            msg.setSentDate(new Date());

            myTransport = mailSession.getTransport("smtp");

            myTransport.connect(smtphost, username, password);

            msg.saveChanges();

            myTransport.sendMessage(msg, msg.getAllRecipients());

            myTransport.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    public static void main(String[] argv) {

SMTPSend smtpSend = new SMTPSend();

smtpSend.msgsend();

}

}
当我运行代码时,我得到以下错误

Exception in thread "main" java.lang.NoClassDefFounderror: SMTPSend
您没有提到用于发送消息的端口。

您必须这样做
SMTP\u PORT=“465”

现在格式更糟糕了…请看,现在请以Java方式缩进代码。您的主要方法在哪里?这才是问题所在,不是这门课。对不起,麻烦了,我是新手。。
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
props.put("mail.smtp.socketFactory.fallback", "false");