发邮件必须通过邮件服务器吗?还有别的什么办法吗?

stoney0914 2004-12-28 11:07:24
发邮件必须通过邮件服务器吗?还有别的什么办法吗?
...全文
505 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zez 2004-12-28
  • 打赏
  • 举报
回复
原先同事自己根据smtp协议直接发送到对方的邮箱...
发送可以不用服务器,但你发给别人,肯定要发送给他的邮件服务器
homeland520 2004-12-28
  • 打赏
  • 举报
回复
是的
ChDw 2004-12-28
  • 打赏
  • 举报
回复
如果你需要发邮件到别人的邮箱,你当然必须利用一个邮件服务器。

你可以找一个另外的邮件服务器,也可以直接连接到他邮箱的服务器都是可以的
genggjh 2004-12-28
  • 打赏
  • 举报
回复
P2P,sourceforge网站上有开源的。
stoney0914 2004-12-28
  • 打赏
  • 举报
回复
楼上的能说说用java怎么实现!谢谢!
yangbc 2004-12-28
  • 打赏
  • 举报
回复
不通过邮件服务器的那叫点对点传输
keithhe 2004-12-28
  • 打赏
  • 举报
回复
你随便填写个邮件地址都可以发吧!

//MailClient.java
import java.awt.*;
import sun.net.smtp.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import javax.swing.event.*;
import javax.swing.border.*;

public class MailClient extends JFrame{

protected SmtpClient sc;
protected JTextField sender,adresses,subject,server;
protected JTextArea message;
protected JButton sendButton;
protected JLabel l1,l2,l3,l4;
protected PrintStream ps;
protected JDialog dialogBox;
protected String toName="";

public MailClient(){

/*******************************Graphical interface**************************/

super("SMTP Mail Client");
getContentPane().setLayout(new BorderLayout());

JPanel header = new JPanel();

JPanel p1=new JPanel(new FlowLayout(FlowLayout.LEFT));
l1=new JLabel(" To: ");
l1.setForeground(Color.black);
p1.add(l1);
adresses=new JTextField(40);

adresses.addFocusListener(new FocusAdapter(){
public void focusGained(FocusEvent e){
l1.setForeground(new Color(98,156,245));
}
});

adresses.addFocusListener(new FocusAdapter(){
public void focusLost(FocusEvent e){
l1.setForeground(Color.black);
}
});

p1.add(adresses);

JPanel p2=new JPanel(new FlowLayout(FlowLayout.LEFT));
l2=new JLabel(" From: ");
l2.setForeground(Color.black);
p2.add(l2);
sender=new JTextField(40);
sender.addFocusListener(new FocusAdapter(){
public void focusGained(FocusEvent e){
l2.setForeground(new Color(98,156,245));
}
});

sender.addFocusListener(new FocusAdapter(){
public void focusLost(FocusEvent e){
l2.setForeground(Color.black);
}
});

p2.add(sender);

JPanel p3=new JPanel(new FlowLayout(FlowLayout.LEFT));
l3=new JLabel(" Subject: ");
l3.setForeground(Color.black);
p3.add(l3);
subject=new JTextField(40);
subject.addFocusListener(new FocusAdapter(){
public void focusGained(FocusEvent e){
l3.setForeground(new Color(98,156,245));
}
});

subject.addFocusListener(new FocusAdapter(){
public void focusLost(FocusEvent e){
l3.setForeground(Color.black);
}
});

p3.add(subject);

JPanel p=new JPanel(new FlowLayout(FlowLayout.LEFT));
l4=new JLabel(" Server: ");
l4.setForeground(Color.black);
p.add(l4);
server=new JTextField(40);
server.addFocusListener(new FocusAdapter(){
public void focusGained(FocusEvent e){
l4.setForeground(new Color(98,156,245));
}
});

server.addFocusListener(new FocusAdapter(){
public void focusLost(FocusEvent e){
l4.setForeground(Color.black);
}
});

p.add(server);


JLabel label=new JLabel("JAVA MAIL CLIENT APPLICATION");
label.setFont(new Font("TimesRoman",Font.BOLD,20));
label.setForeground(Color.blue);
label.setSize(250,30);
label.setHorizontalAlignment(JLabel.CENTER);

header.setLayout(new GridLayout(5,1));
header.add(label);
header.add(p1);
header.add(p2);
header.add(p3);
header.add(p);

message=new JTextArea(70,50);
message.setFont(new Font("SansSerif",Font.BOLD,14));
JScrollPane pScroll=new JScrollPane(message);
pScroll.setBorder(new TitledBorder(new
EtchedBorder(),"Mail Message"));

JPanel p4=new JPanel(new FlowLayout());
sendButton=new JButton("SEND MESSAGE");
sendButton.setMnemonic('e');
sendButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){

if(adresses.getText().equals(""))
dialogMessage(" To: field empty!!! ");
else if(sender.getText().equals(""))
dialogMessage(" From: field empty!!! ");
else if(server.getText().equals(""))
dialogMessage(" Server: field empty!!! ");

else
{
sendMail();

int index=0;
toName=adresses.getText();
index=toName.indexOf('@');
toName=toName.substring(0,index);

dialogMessage(" Your message has been sent to "+toName+" ");
}


}
});
p4.add(sendButton);


getContentPane().add(header,BorderLayout.NORTH);
getContentPane().add(pScroll,BorderLayout.CENTER);
getContentPane().add(p4,BorderLayout.SOUTH);

/********************************************************************/

addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});


setSize(600,500);
setResizable(false);
setVisible(true);


}

/*********************************MAILING********************/
public void sendMail(){

try{
sc = new SmtpClient(server.getText());

sc.from(sender.getText());
sc.to(adresses.getText());
ps=sc.startMessage();

ps.println("Subject: "+subject.getText());
ps.println();

ps.println(message.getText());

sc.closeServer();

adresses.setText("");
sender.setText("");
subject.setText("");
server.setText("");
message.setText("");
}
catch(Exception e){dialogMessage(" Some Error has occured while sending mail. ");}
}

/**********************************MESSAGE***********************/
public void dialogMessage(String str){

dialogBox=new JDialog(new JFrame(),"Message",true);
dialogBox.getContentPane().setLayout(new
BorderLayout());


JPanel p1=new JPanel(new FlowLayout());
JButton okBtn=new JButton("OK");
okBtn.setForeground(Color.black);
okBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dialogBox.setVisible(false);
}
});

p1.add(okBtn);
JLabel l=new JLabel(str,JLabel.CENTER);
l.setFont(new Font("Courier",Font.BOLD,14));
l.setForeground(Color.black);

dialogBox.getContentPane().add(l,BorderLayout.CENTER);
dialogBox.getContentPane().add(p1,BorderLayout.SOUTH);
dialogBox.setResizable(false);
dialogBox.setLocation(270,200);
dialogBox.pack();
dialogBox.show();
}




/**************************************MAIN**********************/
public static void main(String args[]){
new MailClient();
}

}//end of class

yangbc 2004-12-28
  • 打赏
  • 举报
回复
据说这样可以防止垃圾邮件,可是我的sohu垃圾一点没见少
yangbc 2004-12-28
  • 打赏
  • 举报
回复
现在好像直接发送不可以了,你还是要通过邮件服务器来转发,有的大的服务器已经设置不接受没有发送服务器的邮件了

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧