当前位置: 首页>>代码示例>>Java>>正文


Java GmailScopes.all方法代码示例

本文整理汇总了Java中com.google.api.services.gmail.GmailScopes.all方法的典型用法代码示例。如果您正苦于以下问题:Java GmailScopes.all方法的具体用法?Java GmailScopes.all怎么用?Java GmailScopes.all使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.api.services.gmail.GmailScopes的用法示例。


在下文中一共展示了GmailScopes.all方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.google.api.services.gmail.GmailScopes; //导入方法依赖的package包/类
public static void main(String[] args) {	
	
	try {
		System.out.println("----->Sending email message using gmail...");
		GoogleAPIServiceAccountClientData serviceAccountClientID = new GoogleAPIServiceAccountClientData(APP_CODE,
																										 GoogleAPIClientID.of("327116756300-thcjqf1mvrn0geefnu6ef3pe2sm61i2q.apps.googleusercontent.com"),
																									 	 GoogleAPIClientEMailAddress.of("[email protected]account.com"),
																									 	 GoogleAPIClientIDP12KeyPath.loadedFromFileSystem(SERVICE_ACCOUNT_P12_SECRET_PATH),
																									 	 EMail.of("[email protected]"),
																									 	 GmailScopes.all());
		 JavaMailSender mailSender = GMailAPIMailSender.create(serviceAccountClientID);
		
		// [1] - Create a MimeMessagePreparator
		MimeMessagePreparator msgPreparator = _createMimeMessagePreparator(EMail.of("[email protected]"),
																	       EMail.of("[email protected]"),
																	       "A TEST mail message sent using GMail API",
																	       "Just testing GMail API");
		// [2] - Send the message
        mailSender.send(msgPreparator);
		System.out.println("----->Message sent!!");
	} catch(Throwable th) {
		th.printStackTrace(System.out);
	}
}
 
开发者ID:opendata-euskadi,项目名称:r01fb,代码行数:25,代码来源:GMailAPI2Test.java

示例2: main

import com.google.api.services.gmail.GmailScopes; //导入方法依赖的package包/类
public static void main(String[] args) {	
	try {
		// [1] - Create the transport & json factory
		HttpTransport httpTransport = GoogleAPI.createHttpTransport().noProxy();
		JsonFactory jsonFactory = GoogleAPI.createJsonFactory();
		
		// [2] - Create the google credential
		boolean useServerToken = true;
		GoogleCredential credential = null;
		if (useServerToken) {
			GoogleAPIServiceAccountClientData serviceAccountClientID = new GoogleAPIServiceAccountClientData(APP_CODE,
																											 GoogleAPIClientID.of("327116756300-thcjqf1mvrn0geefnu6ef3pe2sm61i2q.apps.googleusercontent.com"),
																										 	 GoogleAPIClientEMailAddress.of("[email protected]account.com"),
																										 	 GoogleAPIClientIDP12KeyPath.loadedFromFileSystem(SERVICE_ACCOUNT_P12_SECRET_PATH),
																										 	 EMail.of("[email protected]"),
																										 	 GmailScopes.all());
			credential = GoogleAPI.createCredentialForServiceAccount(httpTransport,
														   			 jsonFactory,
														   			 serviceAccountClientID);
		} else {				
			credential = GoogleAPI.createCredentialForNativeApp(httpTransport,
														   		jsonFactory,
														   		new GoogleAPINativeApplicationClientData(APP_CODE,
														   												 GoogleAPIClientID.of("327116756300-fd4u232iat8srb3gumlfsqdn244ksc8h.apps.googleusercontent.com"),
														   											     GoogleAPIClientIDJsonKeyPath.loadedFromFileSystem(NATIVE_APP_CLIENT_SECRET_PATH),
														   											     GmailScopes.all()));
		}
		
		// [3] - Create the gmail service
		Gmail gmailService = GoogleAPI.createGmailService(httpTransport,
												 		  jsonFactory,
												 		  APP_CODE,
												 		  credential);
		
		// [4] - Send a test messag
		_sendMessage(gmailService,
					 USER,
					 _createEmail("[email protected]","[email protected]",
							 	  "Test OK server side!",
							 	  "I got it!! It works!"));
		
	} catch(Throwable th) {
		th.printStackTrace(System.out);
	}
}
 
开发者ID:opendata-euskadi,项目名称:r01fb,代码行数:46,代码来源:GMailAPITest.java


注:本文中的com.google.api.services.gmail.GmailScopes.all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。