Java里面通过公司邮箱向外部邮箱发送mail的问题 你用的是这个smtp.sohu.com做邮件服务器,应该是有密码的,你说是用你们公司的邮件服务器,但是你现在用的是sohu.com,所以不对了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是这样的,这个是我随便写的,不方便把公司的邮件服务器放在上面,我现在要通过公司的mail server向外面发邮件,以上程序哪里需要改动呢 smtp.sohu.com 这个不是你们公司的邮件服务器地址吧 直接填写你公司的exchange server ip地址或服务器名称都可以的。 还有一个杀毒软件可以会把邮件发送25端口给禁止了。Macfee就会出现这种情况,自己也查查看。 我是透过公司的mail server向外发邮件的,直接用公司的邮箱向外发邮件是没有问题,也就是说邮件服务器的25端口是没有被禁止的 公司的邮件服务器用的是Notes import javax.mail.*;import javax.activation.*;import java.util.*;import javax.mail.internet.*;public class SendMail { public static void main(String[] args) { try { Properties props = new Properties(); Session sendMailSession; Store store; Transport transport; SmtpAuthenticator sa=new SmtpAuthenticator("adfasdf","pass"); props.put("mail.smtp.host", "smtp.sohu.com"); props.put("mail.smtp.port", "25"); props.put("mail.smtp.auth","true"); sendMailSession = Session.getInstance(props, sa); Message newMessage = new MimeMessage(sendMailSession); newMessage.setFrom(new InternetAddress("[email protected]")); newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]")); newMessage.setSubject("test"); newMessage.setSentDate(new Date()); newMessage.setText("test"); transport = sendMailSession.getTransport("smtp"); transport.send(newMessage); } catch(Exception e) { e.printStackTrace(); } }} class SmtpAuthenticator extends Authenticator{ String username; String password; public SmtpAuthenticator(String s, String s1) { username = s; password = s1; } protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); }} 我用163当mail server,通过163的帐户和密码认证向别的邮箱发mail就可以了,是不是notes的mail server的设置需要做改动呢,请指教,急啊!!!!! 确认公司stmp是否可以通过程式往公司外部邮件地址发送mail,之前我遇到过这种情况,后来得知公司stmp服务器不允许通过程式直接往外发送mail To Maple99:这个问题你是怎么解决的呢,也就是说可以在哪里修改设定呢? 这段代码哪儿有问题,求解释。 Spring Security 如何获取HttpServletRequest对象? Hibernate调用存储过程 返回值的问题 java写数据库备份模块 struts2文件上传问题 关于 Apache + Tomcat 整合原理的疑惑 使用openoffice转pdf文件的问题 j2ee 关于strutstest的问题? J2EE 具体是什么意思? 关于JAVA开发环境 信息技术的发展现状和展望
Macfee就会出现这种情况,自己也查查看。
import javax.activation.*;
import java.util.*;
import javax.mail.internet.*;public class SendMail
{
public static void main(String[] args)
{
try
{
Properties props = new Properties();
Session sendMailSession;
Store store;
Transport transport;
SmtpAuthenticator sa=new SmtpAuthenticator("adfasdf","pass");
props.put("mail.smtp.host", "smtp.sohu.com");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.auth","true");
sendMailSession = Session.getInstance(props, sa);
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress("[email protected]"));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
newMessage.setSubject("test");
newMessage.setSentDate(new Date());
newMessage.setText("test");
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
class SmtpAuthenticator extends Authenticator
{ String username;
String password; public SmtpAuthenticator(String s, String s1)
{
username = s;
password = s1;
} protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(username, password);
}
}