사용자가 전화 번호를 입력하는 텍스트 필드와 사용자가 이동 통신사의 SMS 게이트웨이를 선택하여 Java 응용 프로그램에서 휴대폰으로 전자 메일을 보내는 콤보 상자가 있습니다. 내가 사용하는 때 나는,JComboBox에서 SMS 관련 문자열
String gateway = (String)comboBox_1.getSelectedItem();
또는
String gateway = comboBox_1.getSelectedItem().toString();
내가 오류를 얻고 SMS가 전송하지 않습니다를 텍스트 필드에서 문자열을 잡아 아무 문제가 없지만,하고 있습니다. 여기
는 SMS 메시징 관련 내 코드의 부품 콤보입니다JComboBox comboBox_1 = new JComboBox(carriers);
comboBox_1.setSelectedIndex(-1);
contentPane.add(comboBox_1);
comboBox_1.setRenderer(new PromptComboBoxRenderer("Select Carrier Gateway"));
((JLabel)comboBox_1.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
textField_1 = new JTextField();
contentPane.add(textField_1);
textField_1.setColumns(10);
textField_1.setHorizontalAlignment(JLabel.CENTER);
...
public class SMTPSend {
public SMTPSend() {
}
public void msgSafe() {
String number = textField_1.getText();
String gateway = (String)comboBox_1.getSelectedItem();
// alternatively tried .toString()
String username = "[email protected]";
String password = "password";
String smtphost = "smtp.gmail.com";
String compression = "subject";
String from = "[email protected]";
String to = number + gateway; // where number is the 10 digit phone number and gateway is @SMS_Gateway
String body = "Hello World!";
Transport myTransport = null;
try {
Properties props = System.getProperties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
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();
}
}
...
final String[] carriers = {"@txt.att.net", "@myboostmobile.com", "@messaging.sprintpcs.com", "@tmomail.net", "@vtext.com"};
당신이 만약 내 응용 프로그램에서 더 많은 코드가 필요하므로 제공하기가 더 쉽습니다.
어떤 오류가 발생합니까? –
더 나은 도움을 위해 [최소 완료 예] (http://stackoverflow.com/help/mcve)를 게시하십시오. – Reimeus