⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 postm.java

📁 小型简单的旅馆预订系统. 客户:预定,更改,撤销,会员积分累积,查询预定,会员. 后台:会员更改,房间更改,预定更改,预定信息统计.
💻 JAVA
字号:
package servlet;

import java.util.Date;
import java.util.Properties;

import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

public class postm
{
	public String host="smtp.163.com"; 
	public String user="yiyi7817"; 
	public String password="841209"; 
	public String tto="";
	public String ttitle="";
	public String tcontent="";
	public String sender="";
	public postm()
	{
		host="smtp.163.com"; 
	    user="yiyi7817"; 
	    password="841209"; 
	}
 	
    public void setHost(String host) 
    { 
     this.host=host; 
    } 

    public void setAccount(String user,String password) 
    { 
     this.user=user; 
     this.password=password; 
    } 
    public String getUser() 
    { 
     return user;
     
    } 

    public String getPassword()
    {
    	return password;
    }
	public String getHost()
	{
		return host;
	}

	public String getSender()
	{
		return sender;
	}

	public void setSender(String sender)
	{
		this.sender = sender;
	}

	
	public void setTitle(String title)
	{
		this.ttitle=title;
	}
	
	public void setReceiver(String receiver)
	{
		this.tto=receiver;
	}
	
	public void setContent(String content)
	{
		this.tcontent=content;
	}

	public String getTto()
	{
		return tto;
	}

	public String getTtitle()
	{
		return ttitle;
	}

	public String getTcontent()
	{
		return tcontent;
	}

	public void sendMail()
	{
		
		try{
			
			Properties props=new Properties();
			props.put("mail.smtp.host",host);
			props.put("mail.smtp.auth","true"); 
			Session s=Session.getInstance(props);
			s.setDebug(true);

			MimeMessage message=new MimeMessage(s);

			InternetAddress from=new InternetAddress(getSender()); 
			message.setFrom(from);
			InternetAddress to=new InternetAddress(getTto());
			message.setRecipient(Message.RecipientType.TO,to);
			message.setSubject(getTtitle());
			message.setSentDate(new Date());

			BodyPart mdp=new MimeBodyPart();
			mdp.setContent(getTcontent(),"text/html;charset=gb2312");
			Multipart mm=new MimeMultipart();

			mm.addBodyPart(mdp);
			message.setContent(mm);

			message.saveChanges();
			Transport transport=s.getTransport("smtp");
			transport.connect(getHost(),getUser(),getPassword());
			transport.sendMessage(message,message.getAllRecipients());
			transport.close();
			}catch(MessagingException e){
				System.out.println("error");
			}
			catch(Exception e)
			{
				System.out.println("error2");
			}
	}
	public void doSend(String receiver,String tt,String ct)
	{
		String rece="",content="",title="";
		rece=receiver;
		title=tt;
		content=ct;
		this.setReceiver(rece);
        this.setTitle(title);
        this.setContent(content);
		this.sendMail();
	}
	public void setWelcome(String name,String password)
	{
		String content="",title="";
		title="Welcome to Create Account in Star Hotel Reservation System!";
		content="Hello, "+name+" . This is a welcome mail. Please Remember these information: username: "+name+" ,  password: "+password+" (hashed).";
		this.setTitle(title);
		this.setContent(content);
	}
	public void setConfirm(String name,String lk)
	{
		String content="",title="",link=lk;
		title="Welcome to Create Account in Star Hotel Reservation System!";
		content="Hello, "+name+" . This is an email confirm process. Please click this link to Activate your account:  ";
		content=content.concat(link);
		this.setTitle(title);
		this.setContent(content);
	}
	public void setFindout(String fname,String lname,String lk)
	{
		String content="",title="",link=lk;
		String name=fname+" "+lname;
		title="Find out Password";
		content="Hello, "+name+" . This is an Password renew process. Please click this link to Change your account:  ";
		content=content.concat(link);
		this.setTitle(title);
		this.setContent(content);
	}
	public static void main(String[] args) { 
		postm pm=new postm();
		String email="yiyi7817@msn.com";
		String username="yiyi7817";
		String password="123456789";
		pm.setSender("yiyi7817@163.com");
		pm.setReceiver(email);
        pm.setTitle("hello");
        pm.setContent("test");
        pm.sendMail();
        
	} 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -