C# Sending gmail with uploading large file on Google drive attachment - c#

I need to create a program in c# that can upload to google drive and attach it to email(gmail) and send it to recipients. The file is more than 50mb that is why we need google drive to send. Is there a google api available to do those task all in one? Is that possible? I have been reading solutions here but mostly uploading file to google drive and sending email are separate solutions and I am having a hard time combining those two task. Can somebody direct me if there is a proper code or api to do those task.
The program will provide the following information
sender email: username
sender email: password
upload directory and file
recipient or email receiver

#Mandz Yeah, I'm not sure if there is an automatic way of attaching the file to the Gmail's e-mail, however, the way Gmail handles links is quite interesting:
As you can see, it attaches the link to the attachment, making it in some way automatic.
Here's the link to the GitHub repository:
link
I've decided to make it GUI using WPF and MVVM pattern (using Caliburn.Micro). Hopefully, it won't be too difficult to run the sample app on your end.
Here are the steps that you need to do in order to run the app:
Have a Google account.
Login into https://console.developers.google.com/ (It is a platform where you handle all your tokens etc.)
Create a new project - top left, click on Select a project, new window should appear, click on New Project, name it whatever you want, when that's done, click on Navigation menu (top left), APIs & Services -> Library, Search for Google Drive and Gmail API, enable them both. Then go to Credentials (In APIs & Services), click Create credentials, choose OAuth client ID, you might need to configure consent screen (but I think it's pretty easy, you have to choose either Internal or External and provide the Application Name), in Create OAuth client ID, choose Other, name it whatever you want, Click Ok on the new window, then Download JSON on Credentials Page (on the right), place the file in the same dictionary where the .exe app is. Then create another credential for Gmail token (the same way as above I believe). Place it again in the same dictionary where the .exe app is.
To run the app, you will need .NET Core 3.1 https://dotnet.microsoft.com/download (or just new version of Visual Studio)
Build the app, Click the Choose button to select a file, then Click Upload button.
If the tokens are in the same dictionary, a new website should launch and ask you to log in to an appropriate account (I would choose the same Gmail account where you created these tokens) then if you give access to this app, agree to that. When that's done, a token folder should appear in the same dictionary as the .exe file. The reason why the token folder is created is so you won't have to repeat the 6th step.
A downloadable link should appear, copy it and paste in the Text field in the E-Mail tab.
Type the E-mail address (I would suggest your alt account or something so you can just test it).
A subject field can be empty.
Click Send-Email (now just redo the 6th step)
Some side notes:
I had to create two tokens, for Drive and Gmail APIs, I dunno if it's the quickest way of doing this, I tried to just use 1 token but it didn't want to work.
MainView.xaml is just the things that you see, so it doesn't really matter in this case.
MainViewModel.cs is the file where all the important things for you are.
I would look at UploadFileAsync method, it does upload to the root folder (the main folder of Google Drive), then puts the file to the public so anyone can access the file and download it, then gets the public link to the file.
SendEmail method sends the E-Mail.
I put these methods asynchronous so the app won't just freeze (hopefully it won't be a problem for you).
The code is not perfect but I think it will do as learning material.
Feel free to post any questions about it, below. Good luck.
Edit: If you want link like this instead of full link, you change in string plainText to "<p>test<p>"

Related

C# download from Sharepoint (OneDrive) doesn't work - Alternative check if folder is synced doesn't work too

I programmed an application and would like to download some documents from my companies Sharepoint. However, I get this error message:
Cannot contact web site 'https://*****-my.sharepoint.com/' or the web site does not support SharePoint Online credentials. The response status code is 'Unauthorized'. The response headers are ...
Could it be that my company disabled the option to access the Sharepoint through self-made applications?
After this failure I tried to check if the local Sharepoint folder is synced, this would be enough for me. I just want to make sure that the users have access to the latest documents. Whether they have to sync the folder or access it through the web via an implemented link in the source code.
Well, I used the code from the answer of the following link:
Check if folder is synced
Unfortunately, I always get an empty GUID and as a result the message "Off" like someone in the comment section. I guess it has to deal with the fact that the folders do not have icons, I only have a column with "State" but not an folder icon with a sync icon or something like that.
I guess this is the reason: Icon overlay handlers doesn't work
Is there really no simple way to check if the local stored Sharepoint folders are synced?

How to really send a message to a user in Teams through a bot

The last few days, I checked dozens of samples, docs, blog posts, youtube videos (courses, that I couldn't fine) and I can say I'm still confused and I still without a Teams bot.
Every example I've checked is different in approach, and now I'm pretty sure there are many others like me.
Frequently problems: required input/parameters like service Url, conversation Id, etc. 1. You can't find a explanation for them. 2. You can't find a place where it's explained how to get them.
What I want to achieve
I want a bot on Teams, with a API, with 2 parameters: user email, message. The bot has to send the message to the specified user. That's it.
I'm looking how to:
Create/Setup the Application
Create the actual Bot
Install the application to Teams
I used to create a Teams conversation bot. Hope my experience will help you.
First, download sample provided by microsoft. I uses c# to create this bot, so I copy the '57.teams-conversation-bot' folder and opened it with vs studio. In this sample, I need to modify the configuration in appsettings.json. I need to enter the appid and apppassword.
So the next step is creating an Azure ad application in Azure portal. But if you never create Bot Framework registration resource before, you can create the azure ad application when you create a Bot Framework.By the way, You can leave 'Messaging endpoint' empty now. Please note, when you creating Azure ad application, you can choose to set this application as a multitenant app if your account creating the app is in a different tenant with your teams account.
Now I have a bot framework and an Azure ad app, I can modify appsettings.json, enter the appId and app password. I can get appId in app overview page and get app password when creating client secrets in Certificates & secrets tag.
Now, I need to debug my sample with web chat in the azure portal(Enter the bot framework created just now, you can see Tag 'Test in web chat' in the left panel). So I need to use ngrok to make the bot visit my code in local environment. Running the sample by pressing F5 in vs studio. Opening ngrok.exe and running the command ngrok http -host-header=rewrite 3978. Then I can get a https url, copy that and paste in the 'Messaging endpoint'. Don't forget to add '/api/messages'.
Now sending 'hello' to the bot and you will get default result. When you get the picture below, it means you have made a correct configuration.
Next step is to add this bot to Teams client. First, I add the Teams Channel in the bot I created in the azure portal.
Then I need to modify the manifest file. Replacing the "YOUR-MICROSOFT-APP-ID" with appId creating just now. And creating manifest.zip file which contains the three file in folder TeamsAppManifest.
Next step is uploading the zip file to Teams client. Click the 'Apps' in the lower-left corner and click the 'Upload the custom app' in the bottom of the left panel, then click add. Ok, now I get a team conversation bot.
There -are- a ton of approaches, partly because Teams development is still relatively new, partly because the Bot Framework (the set of tools for buildings Bots in the Microsoft world, both for Teams and otherwise) has also undergone some major changes. That's aside from the various language options (dotnet, node, python, etc.).
What's looking to be a good place to get started though, is the new Teams Toolkit, a plugin for Visual Studio and Visual Studio Code, for building a new Teams project (Tab, Bot, etc.). Have a look here for a link. It's very new though, so some rough edges, but it's aiming to be very comprehensive to get up and running quickly (does a lot of Azure registrations behind the scenes, for example). Check out the latest monthly Teams Developer call, from earlier this week, for a visual run-through: https://www.youtube.com/playlist?list=PLWZJrkeLOrbbTKzV1sQOFAXd_s0BHJDiL (this week's call isn't up yet, but it should be very soon).

File Drag&Drop from Browser to Browser

My asp.net web application is some kind of "document managment system" saving files in the file system of the server.
The stored files are shown in an asp:ListView control and are downloadable as HTTP- Download. But I also want to drag&drop them into another browser window to upload the draged file to an cloud storeage like dropbox or google drive oslt.
I did some research and I didn't find any solution for this problem. I don't know if this is even possible. Maybe someone has an idea how this could be done?
I am pretty sure you can't have a web application doing that for you because it involves having your web language interacting with your computer, to move a local file to another window or tab in the browser.
It would be similar to have Javascript accessing your local files without the user "help". That is not allowed.
Rather than doing that, why not connect to Google Drive or Dropbox API and make the upload yourself?
In the piece of code where you trigger the download, you could also trigger an upload to the desired service.
Here are the API Documentation for the mentioned services:
https://www.dropbox.com/developers/documentation/http/documentation#file_requests-create
https://developers.google.com/drive/api/v3/manage-uploads

Unable to add multiple redirect URLs with Microsoft Live OAuth service

I have an ASP.Net C# Web Application in which I have added Windows Live oAuth authentication (I am not using the code supplied by the Visual Studio project template for oAuth). I have two return pages in my application where the user should come back after authenticating with the Windows Live oAuth Service. The reason I have two end points is to distinguish two different modes in my application based on where the user returns.
Anyways, the problem is that when I add the second URL in the configuration screen of Microsoft Windows live at https://account.live.com/developers/applications/apisettings/, the Microsoft Live page simply does not save it. Here is what I am doing:
Go to https://account.live.com/developers/applications/index
Click Application name and then edit Settings
go To API Settings
Click "Add another redirect URL"
Added my second URL and clicked save.
The second text box where I entered the URL simply disappears and my second URL does not work in the oAuth flow.
If any of you has faced a similar issue, do you have a work around? If this is something Microsoft should fix, where should I raise this bug with Microsoft?
Update: I have also tried a work around of creating two applications, so that each one has one of the return URLs, but Microsoft does not allow two applications with the same root domain URL. :(
I have the same issue.
This is not your fault, and there is nothing other than Microsoft would be able to fix it.

c# using SHDocVw.InternetExplorer. How can I find the URL of the last link clicked? Or the most recent get request URL?

I am accessing the SHDocVw.InternetExplorer from the SHDocVw.ShellWindowsClass(). I can see the page that the browser instance is currently on (the LocationURL property), but what I really need is the last get request that was done for the browser. My specific need is that my application was just launched to handle a file that was downloaded to the user's system via a link on the current web page. I need to know the URL of that file. LocationURL gives me the URL of the page that the link is on, but I need the URL of the file/link.
EDIT: The web application I've been trying to interface with is SharePoint. I wasn't able to find a way to extract the URL of the last clicked link (file downloaded) from Internet Explorer, so now I'm hoping to find a way to get that information from either SharePoint itself, or piggyback on the Name ActiveX control that SharePoint uses to manage the download of MS Office documents. Any SharePoint/Name ActiveX experts out there?
Since you can't get the url from Internet Explorer's history using IUrlHistoryStg::EnumUrls http://msdn.microsoft.com/en-us/library/aa767720%28VS.85%29.aspx
try making sure the file association is setup one the box and that your app can take a file path from the command line to start up.
I added these keys to my registry
[HKEY_CLASSES_ROOT\.sdr]
#="sdrfile"
[HKEY_CLASSES_ROOT\sdrfile\shell\open\command]
#="\"D:\\Shenanigans\\MyGreatApp.exe\" \"%1\""
on a Win7 box and IE/Sharepoint figured it out. If you poke around HKCR you'll see that it can get more complicated to setup file associations, but see if this works.
Sink DWebbrowserEvents2::OnBeforeNavigate2.

Categories