我通过java从手机发送短信到手机但是gmail发送错误信息为
交付给以下收件人永久失败
虽然我的代码执行良好没有错误,我正在使用telenor服务,所以我发现SMTP服务作为公司名称Telenor和SMTP格式化为phonenumber@mobilpost.no:并且在电话的地方没有我给我的no例如03440063315 @ mobilpost.no但我在gmail上收到的消息如下:
Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the server for the recipient domain mobilpost.no by mx.online.no. [193.213.115.10].
The error that the other server returned was:
550 5.1.1 <03440063315@mobilpost.no>... User unknown
----- Original message -----
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=date:from:to:message-id:subject:mime-version:content-type
:content-transfer-encoding;
我的java代码在这里,
package smstext;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
public class MailClient
{
public void sendMail(String from, String to,
String subject, String messageBody) throws MessagingException, AddressException
{
// Setup mail server
String host = "smtp.gmail.com";
String username = "rajiqbalbhatti@gmail.com";
String password = "password";
Properties props = new Properties();
props.put("mail.smtps.auth", "true");
// Get a mail session
Session session = Session.getDefaultInstance(props, null);
// Define a new mail message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
message.setText(messageBody);
// Send the message
Transport t = session.getTransport("smtps");
try {
t.connect(host, username, password);
t.sendMessage(message, message.getAllRecipients());
} finally {
t.close();
}
}
public static void main(String[] args)
{
try
{
MailClient client = new MailClient();
String from="rajiqbalbhatti@gmail.com";
String to = "03440063315@mx.online.no";
String subject="Test";
String message="I'm testing. Do you see this?";
client.sendMail(from,to,subject,message);
}
catch(Exception e)
{
e.printStackTrace(System.out);
}
}
}