Latest Nugets for Outlook REST API? - nuget-package

I want to send emails from my .NET 4.6.1 application using one of our organisation's O365 email accounts. I'm wondering if there's a Nuget package which can help me.
Microsoft.Office365.OutlookServices looks a bit out-of-date, and the comments on the project page don't inspire confidence.
Microsoft.Graph seems more recent, but its code samples use the pre-release Microsoft Authentication Library (MSAL), which it says isn't suitable for production. Maybe I can use Active Directory Authentication Library .NET (ADAL) instead in conjunction with Graph?

The graph library is the official SDK. It is linked from the official Samles and SDKs page.
Even though the MSAL is described as pre-release on the NuGet page, the Github project page describes the Nuget as being from the stable branch.
Your mileage with it may vary, however in my projects I haven't had any issues with the 1.0.304142221-alpha NuGet.
Someone from Microsoft could probably shed some light on it, perhaps come with an indication of a release date of a non-preview NuGet?

For just sending mails, you can use System.Net.Mail like this:
var mailMessage = new MailMessage();
mailMessage.To.Add(new MailAddress(RECEIVER_MAIL_ADDRESS));
mailMessage.From = new MailAddress(SENDER_MAIL_ADDRESS, SENDER_NAME);
mailMessage.Subject = SUBJECT;
mailMessage.Body = BODY;
mailMessage.IsBodyHtml = true;
using (var smtp = new SmtpClient("smtp.office365.com", 587))
{
var credential = new NetworkCredential
{
UserName = USERNAME,
Password = PASSWORD,
Domain = DOMAIN_OPTIONAL
};
smtp.Credentials = credential;
smtp.EnableSsl = true;
smtp.TargetName = "";
await smtp.SendMailAsync(mailMessage);
}

Related

Unable to add a service reference to Dynamics 365 crm in visual studio 2012

I am trying to add service reference to Dynamics 365 CRM using the following API https://[Organization].api.crm8.dynamics.com/api/data/v8.2/ but each time I am getting this window that asks me for credentials....
I tried using the credentials that I use to login to the crm...but they donot work...can someone tell me which credential I should use?..
Why exactly are you trying to add a reference to the CRM web services? Assuming you want to access CRM from server side code, what you need to do is:
Add references to the core CRM SDK assemblies (Microsoft.Crm.Sdk.Proxy.dll and Microsoft.Xrm.Sdk.dll). You get can them from the downloadable SDK or just add the "Microsoft.CrmSdk.CoreAssemblies" NuGet package.
After doing this you'll be able to write code "talking" with CRM. But what you are missing is the actual "connection". There are several ways of obtaining it, but the easiest one is to use the Xrm Tooling helper class, described here - https://msdn.microsoft.com/en-us/library/mt608573.aspx. You'll need to reference the required assemblies or use the "Microsoft.CrmSdk.XrmTooling.CoreAssembly" NuGet package.
After doing all this, you'll be able to successfully code against Dynamics CRM.
CrmServiceClient crmSvc = new CrmServiceClient(ConfigurationManager.ConnectionStrings["MyCRMServer"].ConnectionString);
IOrganizationService orgService = crmSvc.OrganizationServiceProxy;
// Who am I?
WhoAmIResponse whoAmIResp = orgService.Execute(new WhoAmIRequest()) as WhoAmIResponse;
Guid myUserId = whoAmIResp.UserId;
// Get all accounts starting with 'A'
QueryExpression query = new QueryExpression("account");
query.ColumnSet = new ColumnSet("accountid", "name");
query.Criteria.AddCondition("name", ConditionOperator.BeginsWith, "a");
EntityCollection ecoll = orgService.RetrieveMultiple(query);
foreach(Entity account in ecoll.Entities)
{
if(account.Attributes.Contains("name"))
{
Console.WriteLine((string)account["name"]);
}
}
// Update some account
Entity accountToUpdate = new Entity("account");
accountToUpdate["accountid"] = new Guid("_some_guid_here");
accountToUpdate["name"] = "new name";
orgService.Update(accountToUpdate);
If you want to use the type safe approach, you'll need to generate a proxy class - like described here: https://msdn.microsoft.com/en-us/library/gg327844.aspx
Afterwards you'll be able to write code like this:
DataContext data = new DataContext(orgService);
// DataContext is the name of the service context, as defined in the CrmScv tool
var myAccountData = (from a in data.AccountSet
where a.Address1_Telephone1 == "12312313"
select new
{
a.AccountId,
a.Name,
a.EMailAddress1,
a.PrimaryContactId
}).First();
Contact contactToUpdate = new Contact()
{
ContactId = myAccountData.PrimaryContactId.Id,
EMailAddress1 = myAccountData.EMailAddress1
};
orgService.Update(contactToUpdate);
... which is much nicer and less error prone.
From the looks of it you are trying to authenticate through an App outside of the context of Dynamics 365. If you want to authenticate with the Web API this way you will have to connect to Microsoft Dynamics 365 web services using OAuth and authenticate using ADAL
https://msdn.microsoft.com/en-us/library/gg327838.aspx
Here is a walkthrough on how to do it
https://msdn.microsoft.com/en-us/library/mt622431.aspx
Additional note:
If you are using CRM 2013 SDK you may need to update to 6.1.2 for Dynamics 365 Support
https://blogs.msdn.microsoft.com/crm/2017/02/01/dynamics-365-sdk-backwards-compatibility/

Netsuite SuiteTalk - Login

I am trying to use SuiteTalk to retrieve customer records.
I downloaded the v2016.1 WSDL from here: http://www.netsuite.com/portal/developers/resources/suitetalk-documentation.shtml
I used mv package to build the WSDL and generated the jar file.
I create a project in Eclipse and added the jar file. I am using Java.
Here's a snippet of my code. I am stuck here and don't know how to proceed. It looks like I am missing another jar file? like the NetSuiteService?
RecordRef role = new RecordRef();
role.setInternalId("3");
role.setType(RecordType.contact);
Passport passport = new Passport();
passport.setEmail("me#test.com");
passport.setPassword("mypassword");
passport.setRole(role);
passport.setAccount("123456");
Please help me. What do I need to do?
I'm not familiar with the Java bindings, but it looks like you are missing the data center URL configuration.
I'd recommend using the ruby bindings. They are community supported and there's some decent example code demonstrating various common functions.
I work with .net, I think you need to initialize the service to indicate the datacenter that corresponds to you, it is more or less like this:
// Instantiate the NetSuite web services
Service = new Aggregates.DataCenterAwareNetSuiteService(_account);
Service.Timeout = 1000 * 60 * 60;
var appInfo = new ApplicationInfo();
//App info from application netsuite
appInfo.applicationId = cuenta.ApplicationInfo;
// Prepare login credentials for request level login
Service.passport = new Passport()
{
email = _email,
password = _password,
account = _account
};
Service.applicationInfo = appInfo;

Twilio not working in asp mvc

I am trying to implement two factor authentication in my project. For SMS service i use twilio. But when the SendSmsMessage() is called always it says:
core.cs not found error
I have made a lot of search on the internet. But I could not find a solution. Any suggestions.
Twilio developer evangelist here.
I think you're trying to copy the source directly into your code and hence having issues with the dependencies. My suggestion would be to install the Nuget package from Package Manager Console.
Then just run:
Install-Package Twilio
After installing it you should be able to get it going in any file by just doing the following:
using System;
using Twilio;
class Example
{
static void Main(string[] args)
{
// Find your Account Sid and Auth Token at twilio.com/user/account
string AccountSid = "{{ account_sid }}";
string AuthToken = "{{ auth_token }}";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var sms = twilio.SendSmsMessage(from, to, message);
Console.WriteLine(sms.Sid);
}
}
Also, because you mentioned you're trying to do 2FA, it may be worth mentioning another one of our products called Authy. Authy takes away al the complexity in two factor authentication and is obviously powered by Twilio. Here's a link to a tutorial showing how to implement it in .NET MVC.
Let me know if I can help you further.

Connect with Visual Studio 2012 and C sharp to microsoft cloud TFS server

I am building an asp.net webforms site that can connect to our tfs hosted on Microsoft (http://companyname.visualstudio.com) and get data from it. When I run the project with Cassini it runs fine as it gets the authentication from the browser. But I want to do this from code behind.
I have tried various setups like
var tfs = new TfsTeamProjectCollection(CollectionUri, new UICredentialsProvider());
[which is now deprecated as method and should not be used]
or
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(CollectionUri);
or even with
var tfs = new TfsTeamProjectCollection(CollectionUri, new NetworkCredential("windowsliveid","password"));
I have no domain since it is a Windows Liveid
and then
tfs.EnsureAuthenticated();
Also I get the uri through
var CollectionUri = new Uri("https://companyname.visualstudio.com/DefaultCollection/");
Any ideas on how to properly authenticate. I would love to either prompt the auth window or give username and password directly.
------------------------------ SOLVED !!! ---------------------------------
Here is the solution to it after some googling following Martin Woodward's very helpful suggestion.
First alternate credentials have to be activated through the TFS account. Then the code can be changed into this which works fine :)
Just remember that you need to have the latest version of VS 2012 (at least update1) for the code to work. Else you can't reference BasicAuthCredential.
var nc = new NetworkCredential("username", "password");
var bc = new BasicAuthCredential(nc);
var tfsc = new TfsClientCredentials(bc) {AllowInteractive = false};
var tfs = new TfsTeamProjectCollection(CollectionUri, tfsc);
tfs.Authenticate();
And here are the referenced dlls.
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
Take a look at service credentials, or try enabling alternate credentials on your account which will then allow you to authenticate using http basic auth.
You probably want service credentials for what it sounds like you are doing though.

Log in to CRM from ASP.NET

I'm writing an application in which I have to log on to a CRM 2011 server from ASP.NET code. I quickly found this article:
http://msdn.microsoft.com/en-us/library/cc156363.aspx
The problem I'm having is in this bit of code from that article:
//Create the Service
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
service.CrmAuthenticationTokenValue = token;
service.Url = crmurl;
Visual Studio can't resolve CrmService. So I tried to add a web reference to this project and point the web reference at the CRM service I'm using. The URL I'm getting from Settings->Customizations in CRM, and I'm using the Organization Service endpoint. However, after I add that reference CrmService is still unresolvable. What am I doing wrong?
First off, you have linked a CRM 4 MSDN article, some things have changed so you might want try this one instead: Authenticate Users with Microsoft Dynamics CRM Web Services.
Then as an alternative you may want to try the CrmConnection class, its a helper library in Microsoft.Xrm.Client. It means you can use a connection string approach to authenticate with CRM (and let the class takes care of all the hard work).
var connection = CrmConnection.Parse("Url=http://crm.contoso.com/xrmContoso; Domain=CONTOSO; Username=jsmith; Password=passcode;");
var service = new OrganizationService(connection);
var context = new CrmOrganizationServiceContext(connection);
You can also keep the connection strings in config files makes life significantly easier.
Related articles:
Simplified Connection to Microsoft Dynamics CRM.
Sample: Simplified Connection Quick Start using Microsoft Dynamics CRM.
If you're using standard AD authentication with a local environment this answer should work fine: How to Authenticate to CRM 2011?
Actually, the login procedure is heavily dependent on the authentication provider you're targeting. I'm currently in the process of structuring that info in a pedagogic way on my blog so you're welcome to check it out and nag if it's too techy.
There are at the moment four such ways.
Active directory
Live id
Federation
Online federation
Which is applicable in your case, you should know already. If not, there's code for that too uploaded just a few days ago.
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
...
public AuthenticationProviderType GetAuthenticationProviderType(Uri address)
{
IServiceManagement<IOrganizationService> organizationServiceManagement
= ServiceConfigurationFactory.CreateManagement
<IOrganizationService>(address);
return organizationServiceManagement.AuthenticationType;
}
Assuming that you're aiming for AD, you're in luck. It's the easiest.
Uri organizationUrl = new Uri("http ... Organization.svc");
OrganizationServiceProxy organizationService = new OrganizationServiceProxy(
organizationUrl, null, null, null);
If you're aiming for Live Id - that's stingy. I'm still trying to set up a graspable example. The ones at MSDN are just too heavy and confusing. At least when one's dense and lazy like me. More info at mentioned but undisclosed location.

Resources