格式代码用贴

import java.security.Security;
import java.util.Date;
import java.util.Properties;

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.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 * 使用Gmail发送邮件
 * 
 * @author Winter Lau
 */
public class GmailSender {

	public static void main(String[] args) throws AddressException,
			MessagingException {
		Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
		final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
		// Get a Properties object
		Properties props = System.getProperties();
		props.setProperty("mail.smtp.host", "smtp.gmail.com");
		props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
		props.setProperty("mail.smtp.socketFactory.fallback", "false");
		props.setProperty("mail.smtp.port", "465");
		props.setProperty("mail.smtp.socketFactory.port", "465");
		props.put("mail.smtp.auth", "true");
		final String username = "[邮箱帐号]";
		final String password = "[邮箱密码]";
		Session session = Session.getDefaultInstance(props,
				new Authenticator() {
					protected PasswordAuthentication getPasswordAuthentication() {
						return new PasswordAuthentication(username, password);
					}
				});

		// -- Create a new message --
		Message msg = new MimeMessage(session);

		// -- Set the FROM and TO fields --
		msg.setFrom(new InternetAddress(username + "@mo168.com"));
		msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(
				"[收件人地址]", false));
		msg.setSubject("Hello");
		msg.setText("How are you");
		msg.setSentDate(new Date());
		Transport.send(msg);

		System.out.println("Message sent.");
	}
}

 import java.io.*;

public class IO {
	public static void main(String[] args) {
		try {
			// 1. Reading input by lines:
			BufferedReader in = new BufferedReader(
					new FileReader(args[0]));
			String s, s2 = new String();
			while ((s = in.readLine()) != null)
				s2 += s + "\n";
			in.close();

			// 1b. Reading standard input:
			BufferedReader stdin = new BufferedReader(
					new InputStreamReader(System.in));
			System.out.print("Enter a line:");
			System.out.println(stdin.readLine());

			// 2. Input from memory
			StringReader in2 = new StringReader(s2);
			int c;
			while ((c = in2.read()) != -1)
				System.out.print((char) c);

			// 3. Formatted memory input
			try {
				DataInputStream in3 = new DataInputStream(
				// Oops: must use deprecated class:
						new StringBufferInputStream(s2));
				while (true)
					System.out.print((char) in3.readByte());
			} catch (EOFException e) {
				System.out.println("End of stream");
			}

			// 4. Line numbering & file output
			try {
				LineNumberReader li = new LineNumberReader(
						new StringReader(s2));
				BufferedReader in4 = new BufferedReader(li);
				PrintWriter out1 = new PrintWriter(new BufferedWriter(
						new FileWriter("IODemo.out")));
				while ((s = in4.readLine()) != null)
					out1.println("Line " + li.getLineNumber() + s);
				out1.close();
			} catch (EOFException e) {
				System.out.println("End of stream");
			}

			// 5. Storing & recovering data
			try {
				DataOutputStream out2 = new DataOutputStream(
						new BufferedOutputStream(
								new FileOutputStream("Data.txt")));
				out2.writeDouble(3.14159);
				out2.writeBytes("That was pi");
				out2.close();
				DataInputStream in5 = new DataInputStream(
						new BufferedInputStream(
								new FileInputStream("Data.txt")));
				BufferedReader in5br = new BufferedReader(
						new InputStreamReader(in5));
				// Must use DataInputStream for data:
				System.out.println(in5.readDouble());
				// Can now use the "proper" readLine():
				System.out.println(in5br.readLine());
			} catch (EOFException e) {
				System.out.println("End of stream");
			}

			// 6. Reading and writing random access
			// files is the same as before.
			// (not repeated here)

		} catch (FileNotFoundException e) {
			System.out.println("File Not Found:" + args[1]);
		} catch (IOException e) {
			System.out.println("IO Exception");
		}
	}
} // /:~

 

 

import java.io.UnsupportedEncodingException;
import java.security.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeUtility;

/**
 * 用于收取Gmail邮件
 * 
 * @author Winter Lau
 */
public class GmailFetch {

	public static void main(String argv[]) throws Exception {

		Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
		final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";

		// Get a Properties object
		Properties props = System.getProperties();
		props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
		props.setProperty("mail.pop3.socketFactory.fallback", "false");
		props.setProperty("mail.pop3.port", "995");
		props.setProperty("mail.pop3.socketFactory.port", "995");

		// 以下步骤跟一般的JavaMail操作相同
		Session session = Session.getDefaultInstance(props, null);

		// 请将红色部分对应替换成你的邮箱帐号和密码
		URLName urln = new URLName("pop3", "pop.gmail.com", 995, null,
				"[邮箱帐号]", "[邮箱密码]");
		Store store = session.getStore(urln);
		Folder inbox = null;
		try {
			store.connect();
			inbox = store.getFolder("INBOX");
			inbox.open(Folder.READ_ONLY);
			FetchProfile profile = new FetchProfile();
			profile.add(FetchProfile.Item.ENVELOPE);
			Message[] messages = inbox.getMessages();
			inbox.fetch(messages, profile);
			System.out.println("收件箱的邮件数:" + messages.length);
			for (int i = 0; i < messages.length; i++) {
				// 邮件发送者
				String from = decodeText(messages[i].getFrom()[0].toString());
				InternetAddress ia = new InternetAddress(from);
				System.out.println("FROM:" + ia.getPersonal() + '('
						+ ia.getAddress() + ')');
				// 邮件标题
				System.out.println("TITLE:" + messages[i].getSubject());
				// 邮件大小
				System.out.println("SIZE:" + messages[i].getSize());
				// 邮件发送时间
				System.out.println("DATE:" + messages[i].getSentDate());
			}
		} finally {
			try {
				inbox.close(false);
			} catch (Exception e) {
			}
			try {
				store.close();
			} catch (Exception e) {
			}
		}
	}

	protected static String decodeText(String text)
			throws UnsupportedEncodingException {
		if (text == null)
			return null;
		if (text.startsWith("=?GB") || text.startsWith("=?gb"))
			text = MimeUtility.decodeText(text);
		else
			text = new String(text.getBytes("ISO8859_1"));
		return text;
	}
}

 

 

{
                // 导航条
                "moduleType":"12",           //必填,模块类型,不作展示
                "item":
                {
                    "title":"",              //必填,标题
                    "subTitle":"",           //非必填,副标题
                    "titleJump":"",          //非必填,标题跳转链接
                    "subTitleJump":"",       //非必填,副标题跳转链接
                    "styleType":""           //非必填,使用样式
                }
{
                // 导航条
                "moduleType":"12",           //必填,模块类型,不作展示
                "item":
                {
                    "title":"",              //必填,标题
                    "subTitle":"",           //非必填,副标题
                    "titleJump":"",          //非必填,标题跳转链接
                    "subTitleJump":"",       //非必填,副标题跳转链接
                    "styleType":""           //非必填,使用样式
                }
            }
  }

 

 

 

 

{
                // 导航条
                "moduleType":"12",           //必填,模块类型,不作展示
                "item":
                {
                    "title":"",              //必填,标题
                    "subTitle":"",           //非必填,副标题
                    "titleJump":"",          //非必填,标题跳转链接
                    "subTitleJump":"",       //非必填,副标题跳转链接
                    "styleType":""           //非必填,使用样式
                }
            }

 

 

            {
                // 三个图片)
                "moduleType":"102",               //必填,模块类型,不作展示
                "itemList":
                [
                    {     
                        "imageH":"",               //必填,高质量商品图片,
                        "imageL":"",             //必填,低质量商品图片,
                        "jump": "" // 跳转到搜索
                     }
                ]
            }

 

 

 

{
        // 关键字设置
        "moduleType":"13",           //必填,模块类型,不作展示
        "searchList":
         [
                 {
                        "title":"",          //必填,标题
                        "styleType":"",      //非必填,使用样式
                        "jump": ""  // 跳转到搜索
                  }
          ]
}

 

 

{
        // 卖场模块
        "moduleType":"14",            //必填,模块类型,不作展示
        "itemList":
        [
               {
                        "title":"",           //必填,标题
                        "beginTime":"",       //必填,开始时间
                        "endTime":"",         //必填,结束时间
                        "imageH":"",               //必填,高质量商品图片,
                        "imageL":"",             //必填,低质量商品图片,
                        "styleType":"",       //非必填,使用样式
                        "jump": ""  // 跳转到搜索
                }
        ]
}

 

{
        // Tab样式
        "title":"",
        "moduleType":"15",          //必填,模块类型,不作展示
        "itemList":
         [
              {
                        "title":"",         //必填,标题
                        "styleType":"",     //非必填,使用样式
                        "topicId":""        //必填,内容对应链接
                        "updateTime":""     //更新时间
               }
         ]
}

 

#showBetweenTime(2013-08-22 00:00:00, 2013-08-22 23:59:59)
    hello leo
#end
#showBetweenTime(2013-08-23 00:00:00, 2013-08-23 23:59:59)
    hello virgo
#end

 

{
          // 商品图片+价格+标题(两个商品)
           "moduleType":"1",                 //必填,模块类型,不作展示
           "itemList":
             [
                    {
                        "title":"",                   //必填,商品名字
                        "price":"",                  //必填,商品价格
                        "mkPrice":"",	          //商品市场价格
                        "imageH":"",              //必填,高质量商品图片,
                        "imageL":"",               //必填,低质量商品图片,
                        "jump": ""                   // 跳转到搜索
                    }
             ]
}

 

你可能感兴趣的:(C++,c,.net,Security,Gmail)