我编写了以下函数来通过标记未读来修改消息:
- (void)modifyMessageWithId:(NSString *)gmailMessageId
{
__block GTLQueryGmail *query;
query = [GTLQueryGmail queryForUsersMessagesModify];
query.identifier = gmailMessageId;
query.addLabelIds = @[@"UNREAD"];
[self.gmailService executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLGmailMessage *result, NSError *error) {
// Check result here
}];
}
Run Code Online (Sandbox Code Playgroud)
然后我检查了结果,并且有一个错误说id(我认为这意味着query.identifier我设置)是一个未知的字段名称.我也尝试设置,query.messageId并得到一个类似的错误:
(lldb) po error
Error Domain=com.google.GTLJSONRPCErrorDomain Code=400 "The operation couldn’t be completed. (Unknown field name: id)" UserInfo=0xdd37e70 {error=Unknown field name: id, GTLStructuredError=GTLErrorObject 0xdd37cd0: {message:"Unknown field name: id" code:400 data:[1]}, NSLocalizedFailureReason=(Unknown field name: id)}
任何想法如何做到这一点?
我在Openshift上部署了Web服务。目前,我正在开发一种使用我的Gmail帐户在特定时间发送自动电子邮件的方法。
因此,我已经记录了自己两到三天,得出的结论是我有两个选择:
1)使用JavaMail库。2)使用Gmail API。
对于第一个选项,我使用了以下类:
public class EmailSenderService {
private final Properties properties = new Properties();
private String password = "*******";
private Session session;
private void init() {
//ssl
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.socketFactory.port", "465");
properties.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.port", "465");
session = Session.getDefaultInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("eu***@gmail.com",password);
}
});
}
public void sendEmail(){
init();
//ssl
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("eu***@gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("c***6@gmail.com"));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler," +
"\n\n No spam …Run Code Online (Sandbox Code Playgroud) email jakarta-mail google-api-java-client google-oauth gmail-api
我有一个在用户Gmail中查找新邮件的流程.如果消息满足特定的地址条件,则会将消息添加到外部数据库.
我们一直在使用Users.History.List,它返回对它们进行了更改的所有消息.这是非常低效的,因为我们必须随后检查每条消息以查看我们是否已经处理过它.
我们正在考虑使用Users.Messages.List并检查MsgId以查看它是否大于先前的检查(我们存储Id).这里假设MsgId将继续变大.这种做法有缺陷吗?别人在做什么?
非常感谢.
情况:
我正在为我的应用测试Gmail API.
我已经测试了一些请求,它们工作正常.例如获取消息,获取用户历史记录,获取草稿列表等.
基本上所有只读请求都正常工作.
我有一些与其他请求的权限相关的问题,例如当我必须写或删除草稿时.
这是我得到的错误:
(403) Insufficient Permission
Run Code Online (Sandbox Code Playgroud)
代码:
这是初始化应用程序的功能:
public function gmail_init_service()
{
$client = new Google_Client();
$client->setApplicationName("Gmail API test");
$client->setDeveloperKey("MY_KEY");
$client->setClientSecret('MY_CLIENT_SECRET');
$client->SetClientId('MY_CLIENT_ID');
$client->setScopes(array('https://mail.google.com/'));
$client->setAccessToken('{"access_token":"MY_ACCESS_TOKEN","token_type":"Bearer","expires_in":3600,"refresh_token":"MY_REFRESH_TOKEN","created":1433502343}');
$service = new Google_Service_Gmail($client);
return $service;
}
Run Code Online (Sandbox Code Playgroud)
这是删除一个草稿的请求:
public function gmail_delete_draft()
{
$service = $this->gmail_init_service();
// --------------- Get draft list --------------
$list = $service->users_drafts->listUsersDrafts('me');
$draftList = $list->getDrafts();
// --------------- Get draft IDs ---------------
$inbox_draft = [];
foreach($draftList as $mlist)
{
$draftId = $mlist->id;
$optParamsGet2['format'] = 'full';
$single_message = …Run Code Online (Sandbox Code Playgroud) 我正在开发一个能够读取包含图像网址列表的CSV的javascript客户端.
我可以通过jquery-csv读取csv并在html5画布中绘制每个图像.
下一步是将每个图像应用于文本图层,并使用gmail api通过电子邮件发送图像.
所以我的不同之处在于找到一个示例,向我展示如何使用画布并仅使用javascript将其附加到电子邮件中.
我有没有根据multipart gmail指南构建一个json并将其作为指定的POST主体发送?
你能给我一些例子吗?
我有两个gmail帐户,我创建了一个包含五条消息的帖子,并在此页面上使用gmail gapi进行了检索https://developers.google.com/gmail/api/v1/reference/users/threads/get.
这就是我得到的:
正如您所看到的,ID不匹配,尽管它们识别完全相同的字母.为什么会这样,我怎样才能获得统一ID?
PS我这样做的真正原因是我需要使用gmail API发送回复消息,但要做到这一点,您需要知道您回复的消息的ID.如果我回复带有id的消息(不是接收者拥有的消息ID),它只会发送一条"新"消息.
如何使用Gmail API发送回复?
先感谢您.
当我使用GMail API发送电子邮件时,我获得了要向其发送消息的用户的访问令牌,然后在发送消息时,我在From字段中添加了一些值.
但是无论我放在from字段中,电子邮件中的消息都显示为From"Me",并且位于Sent邮件和收件箱中.
有没有办法,我可以使用服务帐户发送电子邮件,这样它就不会显示为From"Me",也不会出现在Sent Mails中.
这个代码snniped:
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,//read from client secret.json file
Scopes,
"user",
CancellationToken.None).Result;
// Create Gmail API service.
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");
WatchRequest body = new WatchRequest()
{
TopicName = "projects/push-notifications-ver3/topics/mytopic",
LabelIds = new[] {"INBOX"}
string userId = "me";
UsersResource.WatchRequest watchRequest = service.Users.Watch(body, userId);
WatchResponse test = watchRequest.Execute();
Run Code Online (Sandbox Code Playgroud)
获取错误:将测试消息发送到Cloud PubSub项目/ push-notifications-ver3/topics/mytopic时出错:用户未被授权执行此操作.[403]
主题是通过订阅创建的,作为主题的所有者给予当前用户许可任何建议用户未授权的原因?
使用Gmail API发送电子邮件时,它会在正文中设置硬行换行符,每行大约78个字符。与此类似的问题可以在这里找到。
我该如何停止?我只是想通过API发送纯文本电子邮件而没有换行符。当前的格式看起来很糟糕,尤其是在移动客户端上(在Gmail和iOS Mail应用程序上经过测试)。
我尝试了以下标题:
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
我有什么想念的吗?
编辑:根据Rebot先生的建议,我也没有运气尝试过此方法:
Content-Type: mixed/alternative
编辑2:这是我发送的消息的确切格式(尝试使用和不使用quoted-printable标题:
From: Example Account <example1@example.com>
To: <example2@example.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Subject: This is a test!
Date: Tue, 18 Oct 2016 10:46:57 -GMT-07:00
Here is a long test message that will probably cause some words to wrap in strange places.
Run Code Online (Sandbox Code Playgroud)
我将收到完整的消息并对其进行Base64编码,然后/gmail/v1/users/{my_account}/drafts/send?fields=id使用以下JSON正文将其发布到:
{
"id": MSG_ID,
"message": {
"raw": BASE64_DATA
}
}
Run Code Online (Sandbox Code Playgroud) gmail-api ×10
gmail ×5
email ×4
google-api ×2
javascript ×2
c# ×1
gapi ×1
gmail-imap ×1
google-oauth ×1
ios ×1
jakarta-mail ×1
php ×1