1. 程式人生 > >JavaMail 發郵件方面的基礎知識

JavaMail 發郵件方面的基礎知識

 

 

郵件伺服器作用:1.接收和傳送郵件2.提供寫郵件的服務

base64Util:
 

package com.test.javamail;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;




import sun.misc.BASE64Encoder;

public class Base64Util {

	/**
	 * @param args add by zxx ,Dec 30, 2008
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BASE64Encoder encoder = new BASE64Encoder();
		System.out.println("please input user name:");
		String username = new BufferedReader(
					new InputStreamReader(System.in))
					.readLine();
		System.out.println(encoder.encode(username.getBytes()));
		System.out.println("please input password:");
		String password = new BufferedReader(
				new InputStreamReader(System.in))
				.readLine();		
		System.out.println(encoder.encode(password.getBytes()));
	}
	

}

smtp協議之間通訊的內容:
 

>>ehlo 伺服器A的賬號 //ehlo
<<auth login plain
>>auth login
<<
>>base64 username
<<
>>base64 password
<<
>>mail from :<伺服器A的賬號@sina.com>
<<
>>rcpt to:<伺服器B的賬號@sohu.com>
<<
>>data
from:<[email protected]
> to:xx subject: date: content!!! . << >>quit 注:此文字為smtp協議通訊的過程 from 到 . 中間的為內容, .為結尾 quit為退出

 注:
1.郵件通用網路埠25

2.ehlo ip地址
可以分別是郵件伺服器還是普通客戶端
原理:輸入的ip地址,是郵件伺服器,就輸入郵件伺服器的名稱,它就會用DNS進行反向解析,看郵件伺服器解析出來的ip地址和電腦的ip地址是否相同,若相同,則認為是郵件伺服器.不是這種情況,則認為是普通郵件客戶端