Google calendar API does not set up recurring event - outlook

I'm making use of the google calendar API to send calendar events from Outlook to my google calendar. I can add events and remove events through the API without any problem.
Now, I want to send a recurring event through the API. The code in my VBA application looks like this:
Dim d As New Scripting.Dictionary
d.Add "kind", "calendar#event"
d.Add "summary", Item.Subject
d.Add "location", Item.Location
d.Add "id", LCase(Item.EntryID)
d.Add "description", Item.Body
Dim d2(4) As New Scripting.Dictionary
d2(0).Add "dateTime", Item.Start
d.Add "start", d2(0)
d2(1).Add "dateTime", Item.End
d.Add "end", d2(1)
d.Add "recurrence", RRuleString
Dim Json As String
Json = JsonConverter.ConvertToJson(d, Whitespace:=" ")
' send the json string via POST
Set httpCall = CreateObject("MSXML2.ServerXMLHTTP")
Dim sURL As String
sURL = "https://www.googleapis.com/calendar/v3/calendars/<my gmail address>/events?sendNotifications=false&fields=etag%2ChtmlLink%2Cid&pp=1&access_token=" + AccessToken
httpCall.Open "POST", sURL, False
httpCall.setRequestHeader "Content-Type", "application/json;charset=UTF-8"
httpCall.Send Json
Dim sReturn As String
sReturn = httpCall.responseText
The value of RRuleString is "FREQ=DAILY;INTERVAL=2;UNTIL=20230226T083000"
When I send the string to google, the response back says ok but the event that is generated on my google calendar is only a single, no-recurring event.
Any ideas why this would not work or how to further test?
Here is a screen shot of my debugging session where you can see the value of RRuleString as well as the returned structure showing the response status text as ok.
Thank you.
NOTE: I modified the string which is being sent to Google to have RRULE: at the beginning of the string. This screen shot shows the value of the Json string being sent to google which I believe contains the correctly formated RRule string.

Related

MediaWiki API login: "Unable to continue login. Your session most likely timed out."

Trying to create an invite only wiki, that we can login to with a bot account once the customer has authenticated using our own webpage on our corporate website.
I've been using the documentation from here:
https://www.mediawiki.org/wiki/API:Login
Anyway I can get a success response from the API sandbox, but the POST from our new API interface webpage errors with "Unable to continue login. Your session most likely timed out."
I get the same message even if I deliberately enter invalid login credentials, so I would imagine it's not getting as far as actually checking the username/password/token. It's really annoying that there's no decent error to work from.
GETting a token via action=query works fine from the same webpage.
Our webpage is a web forms page written in VB (I know).
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = DirectCast(3072, SecurityProtocolType)
ServicePointManager.DefaultConnectionLimit = 9999
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString("https://tmsinsight.com/TMSWiki/api.php?action=query&meta=tokens&type=login&format=json")
Dim j As Object = New JavaScriptSerializer().Deserialize(Of Object)(result)
Dim LoginToken As String = j("query")("tokens")("logintoken")
Response.Write(LoginToken & "<br/>")
webClient.Headers(HttpRequestHeader.ContentType) = "application/x-www-form-urlencoded"
Dim parameters = New NameValueCollection()
parameters.Add("action", "login")
parameters.Add("format", "json")
parameters.Add("lgname", "botusername#botusername")
parameters.Add("lgpassword", "botpassword")
parameters.Add("lgtoken", LoginToken)
Dim responsebytes = webClient.UploadValues("https://tmsinsight.com/TMSWiki/api.php", "POST", parameters)
Dim resultRequest = Encoding.UTF8.GetString(responsebytes)
Response.Write(resultRequest)

Retrieve plain text body from email

Right now I use this code to retrieve the body of an email from Exchange 2010:
i.Load(New PropertySet(BasePropertySet.IdOnly, ItemSchema.Body))
Dim strEmailBodyLines() As String = Split(i.Body.Text, vbCrLf)
Unfortunately I get a HTML response, but I only want plain text from the body in an array (each line). If I replace ItemSchema.Body with ItemSchema.Textbody I get an error it is support on Exchange 2013 and higher.
Can someone tell me how to get the plain text body?
I know the C# code for the same, you may convert this to VB:
// Create empty mail object for holding email details
EmailMessage mail;
// Bind properties from acual email message to mail object
mail = (EmailMessage)Item.Bind(_service, new ItemId(MessageUID));
PropertySet propSet = new PropertySet(BasePropertySet.IdOnly);
// Convert the email body to plain text from HTML
PropertySet propertySets = new PropertySet(BasePropertySet.FirstClassProperties)
{
RequestedBodyType = Microsoft.Exchange.WebServices.Data.BodyType.Text
};
mail.Load(propertySets);

EWS: Add userproperties to an EML when saving it?

In some of my mails, I have stored some userproperties via Outlook...
item.UserProperties.Add("CustID", Outlook.OlUserPropertyType.olText)
item.UserProperties("CustID").Value = custID.ToString
On a Pc (server) without Outlook installed, I want to download mail as EML and store the userproperties (like 'CustID' etc.).
My code for saving the EML:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim service As New ExchangeService(ExchangeVersion.Exchange2013)
service.Credentials = New WebCredentials("my#email.com", "mypsw")
service.Url = New System.Uri("https://outlook.office365.com/EWS/Exchange.asmx")
Dim entryID As String = "00000000C802F40668D27342B788D508E9210A67005DF9A7DEF7194A418C8515031D4262280000E00005DF9A7DEF7194A418C8515031D4262280002A9D18B320000"
Dim id As New ItemId(Convert(service, "my#email.com", entryID))
Dim email As EmailMessage = EmailMessage.Bind(service, id)
Dim ps As PropertySet = New PropertySet(ItemSchema.MimeContent)
email.Load(ps)
Using fileStream = New IO.FileStream("D:\sandbox\_email_test.eml", IO.FileMode.Create)
fileStream.Write(email.MimeContent.Content, 0, email.MimeContent.Content.Length)
End Using
End Sub
Private Function Convert(service As ExchangeService, mailbox As String, entryID As String) As String
Dim originalID As New AlternateId()
originalID.Format = IdFormat.HexEntryId
originalID.Mailbox = mailbox
originalID.UniqueId = entryID 'EntryId retrieved from email in Outlook
Dim altBase As AlternateIdBase = service.ConvertId(originalID, IdFormat.EwsId)
Dim convertedID As AlternateId = DirectCast(altBase, AlternateId)
Dim strConvertedID As String = convertedID.UniqueId
Return strConvertedID
End Function
Is there a way I can store userproperties in an EML? If yes, if I double click the EML to open it in Outlook, can I read back the userproperties from the EML?
Thanks!
User Properties are Mapi/Extended properties which aren't include in the MimeStream of a Message. If you add the properties as X-headers instead then they would be available in the MimeSteam otherwise you would better to export the Message as a MSG file which will give you full fidelity on all MAPI properties. To export as a MSG you will need to use Outlook and maybe look at something like redemption http://www.dimastr.com/redemption/rdo_introduction.htm if you need automation.
Cheers
Glen

Storing emails in sent items of Outlook using add in

I am trying to develop an add in for Outlook in Visual Studio under .net framework 4.0. I used smtp protocol for sending an email from my Outlook addin. I am not able to find the sent mail in sent folder of Outlook.
How do I store sent mail in the sent folder of Outlook?
Till now I have written this code for sending mail.
public bool SendEMail(){
MailMessage mailNew = new MailMessage();
var smtp = new SmtpClient("SmtpServer")
{
EnableSsl = false,
DeliveryMethod = SmtpDeliveryMethod.Network
};
smtp.Port = 587;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("UserName", "password");
smtp.EnableSsl = false;
smtp.Credentials = credentials;
MailAddress mailFrom = new MailAddress("clark#gmail.com");
mailNew.From = mailFrom;
mailNew.To.Add("someone#gmail.com");
mailNew.Subject = Subject;
mailNew.IsBodyHtml = Html;
mailNew.Body = Body;
smtp.Send(mailNew);
return true;
}
I want to add coding for storing the sent mail in sent folder of Outlook.
You will need to create a fake sent item. Note that messages in the Outlook Object Model are created in the unsent state, which cannot be modified.
The only exception is the post item. The following VB script creates a poat item in the Sent Item folder, resets the message class, reopens it as a regular MailItem (which is now in the sent state). Note that you cannot set the sender related properties using OOM alone and you cannot set the sent/received dates.
'create PostItem
set msg = Application.Session.GetDefaultFolder(olFolderSentMail).Items.Add("IPM.Post")
msg.MessageClass = "IPM.Note"
msg.Subject = "fake sent email"
msg.Body = "test"
msg.Save
vEntryId = msg.EntryID
set msg = Nothing 'release the mesage
'and reopen it as MailItem
set msg = Application.Session.GetItemFromID(vEntryId)
'make sure PR_ICON_INDEX is right
msg.PropertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/proptag/0x10800003", -1
set vRecip = msg.Recipients.Add("fakeuser#domain.demo")
vRecip.Resolve
msg.Save
If using Redemption is an option, it lets you set the sent state before the first save (MAPI limitation) and allows to set the sender and date properties correctly:
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set msg = Session.GetDefaultFolder(olFolderSentMail).Items.Add("IPM.Note")
msg.Sent = true
msg.Subject = "fake sent email"
msg.Body = "test"
set vRecip = msg.Recipients.Add("fakeuser#domain.demo")
vRecip.Resolve
'dates
msg.SentOn = Now
msg.ReceivedTime = Now
'create fake sender
vSenderEntryID = Session.AddressBook.CreateOneOffEntryID("the sender", "SMTP", "me#domain.demo", true, true)
set vSender = Session.AddressBook.GetAddressEntryFromID(vSenderEntryID)
msg.Sender = vSender
msg.SentOnBehalfOf = vSender
msg.Save

Reply twice from outlook add in itemadd event

I need to reply twice from an Outlook Add-in item_Add event, once as soon as the mail arrives and once more after some processing. The code for the registered callback looks somewhat as below:
void items_ItemAdd(object Item)
{
Outlook.MailItem mail = (Outlook.MailItem)Item;
Outlook.MailItem reply = mail.Reply();
// Add some stuff to reply body and subject
reply.Send();
Marshal.ReleaseComObject(reply);
// Some processing for few seconds
reply = mail.Reply();
// Update reply body and subject
reply.Send()
// Release reply object
}
The problem I have is the 2 replies are sent out at the end after processing is complete. Is there a way to send the first reply immediately and not wait till the end?
Note, you run the code from the event handler. The handler should return the control flow to Outlook to process your replies.
You can try to use SyncObjects property of the Namespace class to force the synchronization.
Public Sub Sync()
Dim nsp As Outlook.NameSpace
Dim sycs As Outlook.SyncObjects
Dim syc As Outlook.SyncObject
Dim i As Integer
Dim strPrompt As Integer
Set nsp = Application.GetNamespace("MAPI")
Set sycs = nsp.SyncObjects
For i = 1 To sycs.Count
Set syc = sycs.Item(i)
strPrompt = MsgBox("Do you wish to synchronize " & syc.Name &"?", vbYesNo)
If strPrompt = vbYes Then
syc.Start
End If
Next
End Sub
I had modify the code as below:
...
outlookNameSpace = this.Application.GetNamespace("MAPI");
...
void items_ItemAdd(object Item)
{
Outlook.MailItem mail = (Outlook.MailItem)Item;
Outlook.MailItem reply = mail.Reply();
// Add some stuff to reply body and subject
reply.Send();
outlookNameSpace.Session.SendAndReceive(false);
Marshal.ReleaseComObject(reply);
// Some processing for few seconds
reply = mail.Reply();
// Update reply body and subject
reply.Send()
// Release reply object
}
Thanks

Resources