Creating and mailing Excel spreadsheets in Windows Phone 8 apps - excel

I am doing WP, which is contain List of data, and I am trying to add those data into excel sheet.
And this sheet will be attach my mail when I send the mail..
I got one dll but this is still give me error when I generate excel sheet and I press Ok then it will work but I am not satisfied with this is there any other option where I can achieve this scenario..

First and foremost - what DLL are you using? What kind of error are you getting?
Second, if you want to send the document in an email (as an attachment), you won't be able to do that with the out-of-the-box EmailComposeTask. Instead, you could use the LiveMailMessage library:
MailMessage mailMessage = new MailMessage();
mailMessage.Email = "test#email.id";
mailMessage.Password = "somePassword";
mailMessage.AccountType = MailMessage.accountType.MicrosoftAccount;
mailMessage.To = "destination#email.id";
mailMessage.Subject = "Test Subject";
mailMessage.Body = "Test Body";
mailMessage.AddAttachement("/Path/to/Spreadsheet");
mailMessage.Send();

Related

Extract attachments from email and email them as attachments using win32com.client in Python

I am trying to loop through email messages in Outlook using python and get all the attachments in each email, extract them and send them to a different person if it meets a certain criteria. Currently I am saving the attachment and re-attaching it while sending an email. Is there any way where I can do this dynamically and not save the file in the first place
Here is what I have:
import os
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
messages.Sort("[ReceivedTime]", True)
first_msg = messages.GetFirst()
attachments = first_msg.Attachments
attachment = attachments[0]
attachment.SaveAsFile(os.getcwd()+'\\'+attachment.filename)
Outlook = win32com.client.Dispatch("Outlook.Application")
mail = Outlook.CreateItem(0)
mail.To = 'email#test.com'
mail.Subject = 'This is a sample'
attachment = mail.Attachments.Add(myfolder/file.pdf)
mail.Body = 'Sending an attachment through email using python'
mail.Send()
Is there a method where I can bypass saving the file and send the attached file directly?
The Outlook object model doesn't provide any method or property for dealing with attachments on the fly (without saving them to a disk). The Attachment.SaveAsFile method which saves the attachment to the specified path is exactly what you need.
On the other side you may consider a low-level API on which Outlook is built on - Extended MAPI. It allows opening getting property values with streams without saving them to the disk. The PR_ATTACH_DATA_BIN property holds the attachment when the value of the PR_ATTACH_METHOD property is ATTACH_BY_VALUE, which is the usual attachment method and the only one required to be supported. PR_ATTACH_DATA_BIN also holds an OLE 1.0 OLESTREAM attachment when the value of PR_ATTACH_METHOD is ATTACH_OLE. See Opening an attachment for more information.
Not in the Outlook Object Model - saving the attachment as file (if it is a regular olByValue attachment) and reattaching it is your only option. You can attach the whole original message as an attachment though by passing a MailItem object as an argument to Attachments.Add: that will create an embedded message attachment.
As Eugene suggested, you can use Extended MAPI (C++ or Delphi), but it is not accessible in Python. If using Redemption is an option (I am its author), it allows to pass one attachment (RDOAttachment) as an argument to RDOMail.Attachments.Add without saving as file first. That will work for all types of attachments (olByValue, olOLE, olEmbeddedItem, etc.)

Sending Massive emails on excel vba, OLE issue

I hope you're doing great.
I'm using this code to send emails in VBA Excel, but it only works one time, then I have to close Outlook on Task manager. If I don't do this, I get a message that says "Microsoft Excel is waiting for another application to complete an OLE action". The only thing I have to do is close the outlook app on the task manager, and then it works perfectly fine.
Could you please help me fix this issue please? Below I'll post my code
Dim email As Outlook.MailItem
Dim direc As String
Dim body As String
Set A = New Outlook.Application
For i = 2 To ActiveSheet.Cells(Rows.Count, 16).End(xlUp).Row
direc = Worksheets("NewSheet").Cells(i, 16).Value
Set email = A.CreateItem(emailItem)
With email
direc = Worksheets("NewSheet").Cells(i, 16).Value
If (direc <> "0") Then
.To = direc
.Subject = "Notification Test"
body = Worksheets("NewSheet").Cells(i, 14)
.HTMLBody = "<HTML><BODY style=font-size:11pt;font-family:Calibri>This is a notification reminder to let you know that you have <b>" & body & "</b> open contact(s) that you must Update</BODY><br><br>Best Regards, </br></br><br> Anonymous </br></HTML>"
.Display
.Send
End If
End With
Next i
Thank you so much for your time and help.
Do not call both Display and Send. Get rid of the Display line.
I'd suggest trying to run the code in Outlook VBA environment to make sure the issue is not related to security issues when sending emails. The fact is that the Outlook object model generates security issues or give security prompts to users when protected properties or methods are called using automation. Or just may try to call Save instead of Send in the following way:
Set email = A.CreateItem(emailItem)
With email
direc = Worksheets("NewSheet").Cells(i, 16).Value
If (direc <> "0") Then
.To = direc
.Subject = "Notification Test"
body = Worksheets("NewSheet").Cells(i, 14)
.HTMLBody = "<HTML><BODY style=font-size:11pt;font-family:Calibri>This is a notification reminder to let you know that you have <b>" & body & "</b> open contact(s) that you must Update</BODY><br><br>Best Regards, </br></br><br> Anonymous </br></HTML>"
.Save
End If
End With
Next i
If this code works correctly than a security issue is the case.
The Send method may fire an exception when you try to automate Outlook. In this case most probably you are faced with an Outlook security issue. It can also be a prompt issued by Outlook if you try to access any protected property or method. But in your case that can be an exception or error. You get the security prompts/exceptions because Outlook is configured on the client computer in one of the following ways:
Uses the default Outlook security settings (that is, no Group Policy set up)
Uses security settings defined by Group Policy but does not have programmatic access policy applied
Uses security settings defined by Group Policy which is set to warn when the antivirus software is inactive or out of date
You can create a group policy to prevent security prompts from displaying if any up-to-date antivirus software is installed on the system or just turn these warning off (which is not really recommended).
Read more about that in the Security Behavior of the Outlook Object Model article.
Also you may consider using a low-level code on which Outlook is built and which doesn't give security issues - Extended MAPI. Consider using any third-party wrappers around that API such as Redemption.
Another option would be the Outlook Security Manager which allows suppressing Outlook security issues at runtime on the fly.

How to send selected lnbox mail as a attachment through outlook addins using Atl/Com project in VC++

the following is my code:
_ApplicationPtr pApp(Application);
_MailItemPtr pNewMailItem;
pApp->CreateItem(olMailItem,(IDispatch**)&pNewMailItem);
pNewMailItem->put_BCC(L"mailid1");
pNewMailItem->put_Body(L"Mail Send from Visual C++/ATL");
pNewMailItem->put_To(L"mailid2");
pNewMailItem->Send();
I am able to send a new mail but not getting how to attach the selected inbox mail .
Please suggest me some references for proceeding further.
To attach an email you need to access the handle to the Attachmentsobject associated with your MailItem object, and attach your file with a call to Attachments::Add.
Here's a minimal working example. I haven't tested this particular code, so consider a kind of pseudo-code:
_ApplicationPtr pApp(Application);
_MailItemPtr pNewMailItem;
pApp->CreateItem(olMailItem,(IDispatch**)&pNewMailItem);
Outlook::AttachmentsPtr pAttachments;
pNewMailItem->get_Attachments(&pAttachments);
// you need to specify your own values for these parameters
ATL::CComVariant filePath(someFilePath);
ATL::CComVariant displayName("some name");
ATL::CComVariant type(Outlook::olByValue); // to attach a copy
ATL::CComVariant position(1); // add as 1st attachment
Outlook::AttachmentPtr pAttachment;
pAttachments->Add(filePath, displayName, type, position, &pAttachment);

Pragmatically sync office 365 exchange online and GMAIL

So I would want below functionality;
Connect to GMAIL for Business using service account (Already DONE)
Get emails from gmail (Got some API)
Connect to office 365 using oAuth access token (Will be done, I think no issues in it)
Copy the gmail message to office 365 message.
How can I do it?
Here is the code done so far to download message from Google;
Console.WriteLine("Connect to Google API");
Console.WriteLine("=====================");
String serviceAccountEmail = "3512650851-4tpr9073rju4deqtfjp210j07q52hu2j#developer.gserviceaccount.com";
var certificate = new X509Certificate2(#"My Project-d3e5dda28438.p12", "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
User = "<UserEmail for which to download message>",
Scopes = new[] { GmailService.Scope.GmailCompose, GmailService.Scope.GmailModify }
}.FromCertificate(certificate));
var gmailservice = new Google.Apis.Gmail.v1.GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "MyNewProject",
});
try
{
ListMessagesResponse messages = gmailservice.Users.Messages.List("<User Email>").Execute();
IList<Google.Apis.Gmail.v1.Data.Thread> threads = gmailservice.Users.Threads.List("<User Email>").Execute().Threads;
List<Message> responsemessages = new List<Message>();
responsemessages.AddRange(messages.Messages);
foreach(Message msg in responsemessages)
{
Google.Apis.Gmail.v1.UsersResource.MessagesResource.GetRequest gr = gmailservice.Users.Messages.Get("<User Email>", msg.Id);
gr.Format = Google.Apis.Gmail.v1.UsersResource.MessagesResource.GetRequest.FormatEnum.Full;
Message m = gr.Execute();
if (gr.Format == Google.Apis.Gmail.v1.UsersResource.MessagesResource.GetRequest.FormatEnum.Raw)
{
byte[] decodedByte = FromBase64ForUrlString(m.Raw);
string base64Encoded = Convert.ToString(decodedByte);
MailMessage msg2 = new MailMessage();
//msg2.LoadMessage(decodedByte);
}
}
}
catch (Exception ex) { }
Note: The code is very rough for now. Will make it more formal later..
So basically the question is, How can I upload the message row format to office 365 or is there any COPY api?
I am not aware of any C# library/API that handles email synchronization, but maybe Google finds you something.
If not you will have to 'roll your own'. We are doing exactly that with calendar synchronization (in Delphi). The steps to take are:
[Note that I am answering for full synchronization as your question title says]
Analyze the email formats for both systems in detail. Set up data/storage structures that can handle all formats and their differences. You may have to resort to using 'extended/user defined/custom' properties to store properties of system Y in system X, when not present there. You will surely have to use custom properties for storing typical synchronization data: date of last synchronization, date of last change, maybe mutual IDs*
Read emails from both systems over a certain 'synchronization period'.
Do your own comparison looking for differences (added, deleted, modified emails)
Your comparison may have to take configuration/settings into account like Do we synchronize both ways?, When an email is modified on both sides, which one takes precedence?. That's not really necessary, you can define sensible defaults for that. Many synchronisation systems do, they don't ask your for any configuration, but then the user sometimes has to figure out Huh, why did it update this way?).
Write modifications to the external systems.
No small task, I can tell you, so I doubt it fits your your requirement pragmatically ;-) So first invest heavily in searching if someone has already done this.
(And note that asking for libraries is off-topic in SO)
* You will even have to store 'my own ID' as a custom property for each email. If you don't do that you can't distinguish emails that were copied in the external system.

COM Integration from ALBPM - Cannot find IDispatch for '{00020906-0000-0000-C000-000000000046}'

I am trying to use the Office COM components in order to create Word and Excel documents. Unfortunately I can not achieve this because I am getting an error.
Cannot find IDispatch for
'{00020906-0000-0000-C000-000000000046}'
in module
'{00020905-0000-0000-C000-000000000046}',
v8.3
I tried reinstalling Office, my application (ALBPM) and my interface (combsvc) but it is not working.
I want to know how can I install IDispatch, or how can I know if it is installed in the correct module. Some times the error says:
Cannot find IDispatch for
'{000209FF-0000-0000-C000-000000000046}'
... instead of
00020906-0000-0000-C000-000000000046
The code I'm using generate these errors is:
wordAppl.visible = false
wordDocs = wordAppl.documents
contratoTemplate = "C:\\albpmFiles\\mandatory\\aTemplate.doc"
// .doc template
convenioTemplate = "C:\\albpmFiles\\mandatory\\ConvenioModificatorio.doc"
// .doc template
saveContrato = "C:\\albpmFiles\\temp\\"
// where to save.
saveConvenio = "C:\\albpmFiles\\temp\\"
contratoName = "NewContact.doc"
wordDoc = open(wordDocs, fileName : contratoTemplate)
bookmark = item(wordDoc.bookmarks, index : "atrDescripcion")
insertAfter bookmark.range
using text = instSolicitud.atrDescripcion
bookmark = item(wordDoc.bookmarks, index : "atrObjProveedor_atrNombre")
insertAfter bookmark.range
using text = instSolicitud.atrObjProveedor.atrNombre
bookmark = item(wordDoc.bookmarks, index : "atrObjProveedor_atrDireccion")
insertAfter bookmark.range
using text = instSolicitud.atrObjProveedor.atrDireccion
filename = saveContrato + contratoName
end
// Extras - Fin
saveAs wordDoc
using fileName = filename
Any information you have about the IDispatch, or these registry entries, well be very appreciated, even if you can tell me where to find more info about this.
Thanks a lot.
Daniel.
From the error you get I assume that you are using Word 2003.
Have you made sure that the COM brigde service is correctly installed and running?
combsvc -install
combsvc -start
will register combsvc as service and then start it.
Please also have a look at the example for Word at the bottom of page 150 in the ALBPM Reference Guide.
The fact that it is sometimes working and sometimes could be an issue with ALBPM. Are you using the latest version and updates?
Another option - and quite frequent problem with Word automation - would be that the automated instance of Word is displaying a modal dialog box and is waiting for user interaction. You can switch of the display of modal dialogs by setting
Application.DisplayAlerts = 0
However, this will unfortunately not prevent all popups from being displayed.
Is there actually an instance of Word started? If so, can you make the Window visible and see if documents can be opened or if there is a popup blocking the application?
Daniel,
I'm taking a stab in the dark here. It looks like you're using BEA systems Aqualogic BPM which I have a feeling is a Java based tool. From digging about it looks like combsvc is actually a COM bridge service to allow ALBPM to speak to COM from Java:
http://edocs.bea.com/albsi/docs60/studio/index.html?t=studio/catalog/catalog_component/COM/c_COM_Bridge.html
I'm thinking this is your point of failure.
About your question on IDispatch, you don't actually install IDispatch. IDispatch is a interface used by COM to expose objects, methods and properties to late bound COM automation clients such as scripting languages (e.g. ASP or VBScript). It's part of the infrastructure of COM, if this was broken you'd see lots more problems with your machine.
I'd probably advise popping a question in here:
http://forums.oracle.com/forums/forum.jspa?forumID=560
To inspect installed COM Interfaces on your PC i suggest you download oleview.exe which is part of the Windows 2003 resource Kit
I actually have {00020906-0000-0000-C000-000000000046} but also no IDispatch interface and get a "Class not registered" error when trying to create an instance of it. My home PC doesn't have office installed just the Office tools which is most likely the cause.
In the past when automating Office Applications i was always able to talk to a version independent ProgID's such as "Excel.Application". Are you sure your referencing the right COM Objects ? Check it out in oleview or give us some more code to munch on :)
The code I am using is this, but I can not even see the first log, so I assume thereĀ“s an error with the conection, not with the code
wordAppl.visible = false
wordDocs = wordAppl.documents
contratoTemplate = "C:\\albpmFiles\\mandatory\\aTemplate.doc"
// .doc template
convenioTemplate = "C:\\albpmFiles\\mandatory\\ConvenioModificatorio.doc"
// .doc template
saveContrato = "C:\\albpmFiles\\temp\\"
// where to save.
saveConvenio = "C:\\albpmFiles\\temp\\"
contratoName = "NewContact.doc"
wordDoc = open(wordDocs, fileName : contratoTemplate)
bookmark = item(wordDoc.bookmarks, index : "atrDescripcion")
insertAfter bookmark.range
using text = instSolicitud.atrDescripcion
bookmark = item(wordDoc.bookmarks, index : "atrObjProveedor_atrNombre")
insertAfter bookmark.range
using text = instSolicitud.atrObjProveedor.atrNombre
bookmark = item(wordDoc.bookmarks, index : "atrObjProveedor_atrDireccion")
insertAfter bookmark.range
using text = instSolicitud.atrObjProveedor.atrDireccion
filename = saveContrato + contratoName
end
// Extras - Fin
saveAs wordDoc
using fileName = filename

Resources