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

📄 mytimertask.java

📁 First of all, the Applet-phone is a SIP User-Agent with audio and text messaging capabilities. But
💻 JAVA
字号:
/* * Timer.java * * Created on September 24, 2003, 2:27 PM */package gov.nist.examples.mail;import javax.sip.message.*;import javax.sip.header.*;import javax.sip.address.*;import javax.mail.*;import javax.mail.internet.*;import java.util.*;/** *  * @author  DERUELLE Jean */class MyTimerTask extends TimerTask {	private Response response;	/** Creates a new instance of Timer */	public MyTimerTask(Response response) {		this.response = response;	}	/**	 * The listener can be notified by the timer that the time has been elapsed.	 * and so we will send a mail to callee.	 * @param the Timer	 * @param the sip address of the guy who tried to call	 */	public void run() {		System.out.println("Time since the 180 Ringing has been elapsed !");		System.out.println("We are sending an email...");		try {			Properties props = new Properties();			props.put("mail.smtp.host", "smtp.nist.gov");			// Get a Session object			Session session = Session.getDefaultInstance(props, null);			// construct the message            			javax.mail.Message msg = new MimeMessage(session);			FromHeader fromHeader =				(FromHeader) response.getHeader(FromHeader.NAME);			SipURI fromUri = (SipURI) fromHeader.getAddress().getURI();			String fromAddr = fromUri.getUser() + "@" + fromUri.getHost();			msg.setFrom(new InternetAddress(fromAddr));			ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);			SipURI toUri = (SipURI) toHeader.getAddress().getURI();			String toAddr = toUri.getUser() + "@" + toUri.getHost();			msg.setRecipient(				javax.mail.Message.RecipientType.TO,				new InternetAddress(toAddr));			msg.setSubject("Automatic Message");			//msg.setText(request.getHeader(FromHeader.NAME).toString()+ " tries to call you");			msg.setHeader("X-Mailer", "Gateway-Busy");			msg.setSentDate(new Date());			msg.setContent(" I  tried to call you", "text/plain");			// send the thing off                   			Transport.send(msg);			System.out.println("\nMail was sent successfully.");		} catch (Exception e) {			e.printStackTrace();		}	}}

⌨️ 快捷键说明

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