Google Contacts V3, retrieving GMail contacts only - google-contacts-api

I have the following code that works fine. But the issue is that the call retrieves thousands of contacts (most having only email). I want to download only those contacts that are listed in "Contacts" tab in GMail. I had to set a high "NumberToRetrieve" and then have to filter those with more information other than just email.
Dim cr As New ContactsRequest(settings)
Dim query As New ContactsQuery(ContactsQuery.CreateContactsUri("default"))
query.NumberToRetrieve = 5000
query.OrderBy = ContactsQuery.OrderByLastModified
query.SortOrder = ContactsQuery.SortOrderDescending
Dim f As Feed(Of Contact) = cr.Get(Of Contact)(query)
As usual this Google API is also poorly designed. At least in the .Net wrapper of the API I don't see anything that I can use to retrieve only GMail contacts or add a filter such as "where Address exists". Any inputs?
EDIT
Based on the feed back, I scrolled through all contacts groups to find the group "Contacts".
Dim groupquery As New GroupsQuery(GroupsQuery.CreateGroupsUri("default"))
Dim fgrp As Feed(Of Group) = cr.Get(Of Group)(groupquery)
Dim GroupAtomId As String = ""
For Each gr In fgrp.Entries
If gr.Title.Contains("Contacts") Then
GroupAtomId = gr.Id
Exit For
End If
Next
then used GroupAtomId, query.Group = GroupAtomId. Seems to be working ok.

For retrieving all the contacts from Contacts tab in Gmail, you have to specify the group value(Group) in the query as mentioned here and also for retrieving just the contacts in Contacts tab in Gmail, the group value would be just Contacts as shown here
Hope that helps!

Related

Why does adding attachments to access DB via script generate errors

I'm writing a script that brings emails from an O365 mailbox into MS Access.
Accessing the emails, and exporting the attachments all works fine.
Records can be created in the DB with sender, date/time, subject, body etc.
However, I am unable to add the attachments into the DB's attachment field.
This line always generated a type mismatch error:
Set rsAttach = rstDocs.Fields("Attachments").Value
rstDocs already was used to update the other fields in the record - no issue.
But I need the rsAttach object to load the file attachment.
Already tried numerous variations of creating and defining the rsAttach object. I Tried the online examples and I'm basically as per the book from MSDN and other examples from this web site.
omEmail is the email object from Outlook. Its already saved in TmpPath when we get to here.
Set cn = CreateObject("ADODB.Connection")
Set rstDocs = CreateObject("ADODB.Recordset")
Set rsAttach= CreateObject("ADODB.Recordset")
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\data\CustService.accdb';Persist Security Info=False;"
cn.Open
rstDocs.Open "Documents;", cn, adOpenKeyset, adLockPessimistic, adCmdTable
rstDocs.AddNew
rstDocs("Sender").Value = omEmail.SenderEmailAddress
For Each Attachment In omEmail.Attachments
Set rsAttach = rstDocs.Fields("Attachments").Value ' ERROR HERE
rsAttach.AddNew
rsAttach.Fields("FileData").LoadFromFile TmpPath + Attachment.FileName
rsAttach.Update
Next
rstDocs.Update
rstDocs.Close
rstDocs.Fields("Attachments").Value returns an ADO Field object, not a Recordset like you seem to be expecting, so you can't add a record to that field (rsAttach.AddNew).
If you want to store attachments as individual records, you can create a separate Attachments table in which you have an ID field that is the same as the ID of the e-mail record in rstDocs. Please take a look at this very similar question: Handling fields of Attachment type in MS Access using ADO
Documents table:
EmailID as Number
Sender as Text
Subject as Text
Date as Date/Time
...
Attachments table:
EmailID as Number
FileData as Number
Also, the ADO Field object does not have a LoadFromFile method. You will have do load the data and set it to the Field object's Value property.

How to get current logged in user id in access-db 2016

I'm making a students management system in access, in which I have made a signup table named as students and after that I made it's form and it's saving data in table and after that I made login form which is working fine, and after logging in it's showing personal details form (I have set that) and which also stores data, and in personal details table I have a field named student_id_fk which stores the primary key of that user which is logged in but I am confused that how to get currently logged in user id is there any way?
Simplest way would be to use Environ("username")
Alternatively you may use below function or call Windows API
Function getUsername() As String
Dim WshNetwork As Object
Set WshNetwork = CreateObject("WScript.Network")
getUsername = WshNetwork.UserName
Set WshNetwork = Nothing
End Function

What are all the fields available in a Notes email document in VBA

I have written VBA code to send an email from a group mailbox. I set the principal field to say where the mail comes from. It almost works correctly, putting the message in the sent items of the group mailbox. Even though I have the group mailbox name in the Principal field, it still says it was sent my me. I discovered that whichever user looks at the message in sent items, it says it was sent by that user (it is a dynamic field). I want to set that From field, and I discovered I can do that with something like '.from = "(User Name)"'.
So I am aware of the basic variables available, such as .SendTo, .CopyTo, .Principal, .From. But I have done web searches and I can't figure out how to get a comprehensive list of all the variables available. Hopefully someone can point me to some documentation that lists these?
For reference here is my code:
Function EmailFromNotes(strSendTo As String, strCopy As String, strSubject As String, _
strText1 As String, strText2 As String, strText3 As String, _
strText4 As String, strText5 As String, strAttachment As String, strFrom as String)
Dim notesdb As Object
Dim notesdoc As Object
Dim notesrtf As Object
Dim notessession As Object
Dim i As Integer
Dim AttachME As Object 'The attachment richtextfile object
Dim EmbedObj As Object 'The embedded object (Attachment)
Set notessession = CreateObject("Notes.Notessession")
''''''''Group Mailbox'''''''''''''''''''''''''''''''''''''''''''''''''
Set notesdb = notessession.GetDatabase("Servername", "mailin\GroupMailbox.nsf")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Open the mail database in notes
If notesdb.IsOpen = True Then
'Already open for mail
Else
notesdb.OPENMAIL
End If
Set notesdoc = notesdb.CreateDocument
Call notesdoc.ReplaceItemValue("Subject", strSubject)
Set notesrtf = notesdoc.CreateRichTextItem("body")
Call notesrtf.AppendText(strText1 & vbCrLf & strText2 & vbCrLf & strText3 & vbCrLf & strText4 & vbCrLf & strText5)
'''strCopy = "michael.thain#pnc.com"
notesdoc.SendTo = strSendTo
notesdoc.CopyTo = strCopy
notesdoc.from = strFrom
''''''''Group Mailbox'''''''''''''''''''''''''''''''''''''''''''''''''
notesdoc.principal = "Group Mailbox Name"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If strAttachment = "" Then
Else
Set AttachME = notesdoc.CreateRichTextItem(strAttachment)
Set EmbedObj = AttachME.EmbedObject(1454, "", strAttachment)
End If
Call notesdoc.Save(True, False)
notesdoc.SaveMessageOnSend = True
Call notesdoc.Send(False, strSendTo)
Set notessession = Nothing
End Function
Unlike many other mail systems, Lotus Notes is finicky about spoofing the From field. The NotesDocument.Send() method doesn't want you to do it, and will override what you put in there. The Principal field is provided so you can say who you are sending on behalf of, but the From is supposed to be the true name of the actual sender. If you look at the document properties for the message in your Sent folder, I believe you'll find that the From field does indeed contain your name, not the name that your code is trying to put in that field!
There is a way around this, at least for the Sent message. Instead of relying on the SaveMesasageOnSend property, you can just use NotesDocument.Save() to write the document directly to the group mailbox, making sure that you set the PostedDate and not the DeliveredDate so that it will appear in the Sent view. It will be missing other fields that the Domino router would normally have added for you, though, like the MessageID and a few others -- but that might not be important for you. The message should still be viewable. In any case, as complex as it is, the formulas in the fields on the Memo form and its associated subforms in the mail template are your ultimate guide for figuring out how what the user sees is related to the actual values that are stored in the document.
If you're also concerned about making sure that recipients don't see your name, there's another trick. It involves directly writing the message to the router mailbox (the mail.box file). I've seen some systems, however, where there's code in place to prevent spoofing even if you do this, so it's something you'll have to try and see if it will work.
BTW: Are you asking about what the users see when they look at the index of the Sent view? That should be showing the value in the Principal field. Or are you asking about what the users see when go the Sent view and open the message? That should display the Principal field, followed by a newline and then "Sent by:" the From field. (Bear in mind that the From field is not likely the value that your code set due to the anti-spoofing provisions that I described.) Does this match what you are seeing?
Mail fields are defined by an RFC for all mails in general.
http://en.wikipedia.org/wiki/Email#Message_header
RFC 5322 https://www.rfc-editor.org/rfc/rfc5322
In the RFC 5322 Standard the field From has a different purpose than in Lotus Notes, because it is always identifying the owner of the mail.box. Instead of using the field Principal to identify the owner of the mail.box in which an email was written, the field Sender is used to identify the effective user who produced the email.
The field Principal is not (or better said no longer) accepted in the email header by many email providers and bounced back referring to being not RFC 5322 compliant. In messages produced by LotusScript directly in a document saved in the mail.box, you should use the field From instead of the field Principal and add the field Sender for the email address of the effective sender (sent by), who in a regular Lotus Email would be in the field From. If you prefer to have all replies to the effective sender instead of the person identified in the field From (original LN field Principal), you need to add the field ReplyTo with the same address as in der field Sender.

Exchange Web Service managed, get deleted appointments

I am about to write a ews-application to connect exchange with another calendar programm. What occured to me, how do I get to know, which appointments get deleted on exchange? Is there a way to tell? I couldn't find it in the API and documentation.
Thanks in advance.
Depending on how a user deletes an appointment (or any item), different things are done:
Soft-Delete: The item is moved to the recycle bin of the mailbox.
Hard-Delete: The item is instantly removed.
You have multiple ways to get information about deleted items:
Query the folder using a FindItems call and select ItemTraversal.Associated in the Traversal property of the ItemView. Note: This requires Exchange 2010.
Use the SyncFolderItems at one time and store the synchronization cookie somewhere. Later, execute the SyncFolderItems again using the previously stored cookie. Exchange will now give you a detailed list of changes which happened to the folder.
Query the Recycle bin for appointments. They will most likely have come from the default calendar of the user.
I wrote a service that syncs EWS Calendar Appointments to a Sql Table.
For deletion after Inserting/Updating changes if there is a row in the database and not in EWS I will delete it, as this means it was deleted in Exchange. I use GUIDs to track the appointment in database and exchange. Exchange web services: why is ItemId not constant? [continued]
Performance is decent with just couple dozen appointments, I will try it on much larger dataset.
Dim appointmentGuid As New List(Of String)
For Each appointment In appointments 'appointments is IEnumerable(Of Appointment) from EWS
Dim guid As String = GetGuidForAppointment(appointment)
If String.IsNullOrEmpty(guid) Then
SetGuidForAppointment(appointment)
guid = GetGuidForAppointment(appointment)
End If
appointmentGuid.Add(guid)
'Upsert rows
...
Next
'Delete orphaned rows
Using sqlConnection As New SqlConnection(ConnectionString)
Dim deleteScript As New StringBuilder()
Using sqlCmd As New SqlCommand("SELECT ID FROM Appointments", sqlConnection)
Using sqlDataReader As SqlDataReader = sqlCmd.ExecuteReader()
sqlConnection.Open()
While sqlDataReader.Read()
Dim guid As String = sqlDataReader.GetString(0)
If Not appointmentGuid.Contains(guid) Then
deleteScript.AppendFormat("DELETE FROM Appointments WHERE ID = '{0}'; ", guid)
End If
End While
End Using
End Using
If deleteScript.Length > 0 Then
Using sqlCmd As New SqlCommand(deleteScript.ToString(), sqlConnection)
sqlCmd.ExecuteNonQuery()
End Using
End If
End Using

MS Access - Mass Emailing?

I'm using MS Access to create a database with over 5000 contacts. These contacts are separated up into which employee the contact belongs to, and then again into categories for easy searching. What I want to do is create a button that will open up a query in table form (simple), then have check boxes so an employee can select, for example, 100 contacts to send an email to out of the 110 in the table, and then send a mass email such as a newsletter (not so simple!). I've been going nuts trying to work out how to do this as I don't really understand programming (I'm a temp thrown into this job and just doing the best I can) and all I can find on the matter is something about loops (no idea!) and that I need software to do this.
Any solutions for me please? I'd like to avoid buying/installing software if possible and if you do have an answer, please make it as simple as possible...
Thanks in advance!
Kate
I have just created the following working example in MS Access 97.
A sample table (I tested the code with valid e-mail addresses):
ID Name Email
1 Rics rics#stack.com
2 Kate kate#stack.com
3 X x#stack.com
A form with one button.
The following code is being performed when the button is clicked:
Private Sub Mail_Click()
Dim r As Recordset
Dim email As String
Set r = CurrentDb.OpenRecordset("select * from Addresses")
Do While Not r.EOF
email = r(2)
DoCmd.SendObject acSendNoObject, Null, Null, email, Null, Null, "Test subject", "Message body of the test letter", False, Null
r.MoveNext
Loop
r.Close
End Sub
I hope you could insert it into your application.
Got it working :)
The code was great but it needed some tweaking to work specifically with my data. After a lot of errors popping up this is what I finally came up with:
Dim r As Recordset
Dim Email As String
Set r = CurrentDb.OpenRecordset("select Email from FranksFinanceBrokers")
Do While Not r.EOF
Email = Email & r(0) & ";"
r.MoveNext
Loop
r.Close
DoCmd.SendObject acSendNoObject, Null, Null, "", "", Email, "", "", True, Null
End Sub
Thanks for ur helps guys!
I think you're going to need to learn some VBA coding to get this done. This tutorial might be useful.
Heres a way to send email from access.
Here's another resource for sending e-mail through MS Access
The answer that rics has supplied will send an e-mail to everyone in a recordset, but it sounds like maybe what you are wanting to do is send a single e-mail to a custom distribution list. To do that, tweak rics' code to build up the address string something like this:
Private Sub Mail_Click()
Dim r As Recordset
Dim email As String
Set r = CurrentDb.OpenRecordset("select * from Addresses")
Do While Not r.EOF
email = email & r(2) & ";"
r.MoveNext
Loop
r.Close
DoCmd.SendObject acSendNoObject, Null, Null, email, Null, Null, "Test subject", "Message body of the test letter", False, Null
End Sub
Kate,
Sorry to say that there is no specific "magic" code for what you plan to to. You will have to write something. My solution would be:
Create a form with 3 controls: 1 text control, 1 listbox control.,1 "send" button
The text control contains the text to send
The list control displays all my available emails (populated with a recordset)
Multiselect will be enabled, so that I can select multiple items in the list
By a click on the button, I will
Concatenate all selected emails to get a "sendTo" string such as
sendTo = "bla#bla.com;blo#blo.com".
Call the doCmd.sendObject method using sendTo + the text string as an argument
Options could be to
Have an extra control for email subject
Keep a trace of sent mails in a table (subject, text, date, people reached). It could be as basic as "one record per mail" with a memo field to record the sendTo text string (Of course you could build something smarter with multiple tables to stick to the many-to-many relation that can be established between your people table and your mail table, but you might not need it)
There are a couple of ways to get around the missing e-mail addresses. The easiest is to adjust your SQL to exclude them:
select Email from FranksFinanceBrokers WHERE (Email IS NOT NULL) AND (Email <> "")
The other approach would be to add an IF statement to the string building code:
IF Not IsNull(r(0)) AND r(0) <> "" THEN Email = Email & r(0) & ";"
I would just filter it at the SQL level -- more efficient and just easier.
Would it be easier to buy software to do this? Yes, but where's the challenge in that? :-) You are already most of the way there, so I'd stick with it.
Emailing from Access has a number of pitfalls, not least of which is that doing so can make you look like a spammer and cause problems with your email host. Plus, there are a bunch of security issues. The best source for information on this is Tony Toews's Email FAQ.