How can I retrieve the payers email address from a webhook event using the .NET SDK? I need the email to create a purchase with LeadDyno.
UPDATE
Here's how you do it...
var requestBody = string.Empty;
using (var reader = new StreamReader(HttpContext.Request.InputStream))
{
requestBody = reader.ReadToEnd();
}
JObject webhookEvent = JObject.Parse(requestBody);
payerEmail = webhookEvent["resource"]["payer"]["payer_info"]["email"].ToString();
Related
I'm using the send grid api to send emails in my c# app, and I can't seem to figure out how to send an email with multiple attachments. I can send an email with a single attachement, but not multiple. I can see that there are four methods used for attachments(see below), but there is only one that allow you to send a list of attachements "IEnumerable attachments", however it's a return type is void. Can someone tell me how to send multiple attachments using the send gris api?
[![Send Grid methods for addding attachments](https://i.stack.imgur.com/Obf3n.png)](https://i.stack.imgur.com/Obf3n.png)
public async Task<SendResponse> SendHTMLWithAttachmentSendgrid(List<EmailAddress> recipientEmailList, string subject, string htmlContent, string[] attachmentFilePaths, bool showAllRecipients = false)
{
SendResponse emailResponse = new SendResponse();
try
{
List<SendGrid.Helpers.Mail.Attachment> attachments = new List<SendGrid.Helpers.Mail.Attachment>();
SendGrid.Helpers.Mail.Attachment attach = null;
//The total size of your email, including attachments, must be less than 30MB.
foreach (string item in attachmentFilePaths)
{
var stream = File.OpenRead(item);
//string[] contentArray = fileName.Split('.');
//string contentType = contentArray[1].ToString();
var streamCount = stream.ToString();
System.IO.BinaryReader br = new System.IO.BinaryReader(stream);
byte[] bytes = br.ReadBytes((Int32)stream.Length);
string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
string[] filePathArray = item.Split('\\');
string fileName = filePathArray.LastOrDefault();
attach = new SendGrid.Helpers.Mail.Attachment() { Filename = fileName, Content= base64String };
attachments.Add(attach);
}
var from = new EmailAddress(DefaultSenderEmailAddress);
var msg = MailHelper.CreateSingleEmailToMultipleRecipients(from, recipientEmailList, subject, string.Empty, htmlContent, showAllRecipients = false);
MailHelper.CreateSingleEmailToMultipleRecipients(from, recipientEmailList, subject, string.Empty, htmlContent, showAllRecipients = false).AddAttachments(attachments);
var response = await this.SendGridClient.SendEmailAsync(msg);
}
catch (Exception ex)
{
_logger.LogError($"The following error occurred:{ex.Message}.");
}
return emailResponse;
}
I'm expecting to send multiple attachments in my email, using the Send Grid Api
I am trying to get DeviceToken of device in Xamarin iOS through RegisteredForRemoteNotifications and save it to Preferences, through API I save DeviceToken to database Server.
AppDelegate.cs
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
byte[] bytes = deviceToken.ToArray<byte>();
string[] hexArray = bytes.Select(b => b.ToString("x2")).ToArray();
DeviceToken = string.Join(string.Empty, hexArray);
Preferences.Set("TokenDevice", DeviceToken);
}
I have saved the DeviceToken to the database, the DeviceToken of the device I get:
6b60feecad920471ccde5a3447ab22d3f820abae821daeac726cc7e6d0863465
I wrote an API to send notifications to that device:
[HttpPost]
public void SendNotification(string devicetoken, string title, string body, string link, string icon)
{
try
{
dynamic data = new
{
to = devicetoken, // Uncoment this if you want to test for single device
// registration_ids = singlebatch, // this is for multiple user
priority = "high",
notification = new
{
title = title, // Notification title
body = body, // Notification body data
link = link, // When click on notification user redirect to this link
icon = icon
}
};
//var serializer = new JavaScriptSerializer();
var json = JsonConvert.SerializeObject(data);
Byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(json);
string SERVER_API_KEY = "AAAAqOId6Is:APA91bHJ5pQgLlanU8gwQwnpxdBlKS00i1xxxxxxxxxxxxxxxxxxxxxxxxxxx";
string SENDER_ID = "72xxxxxxxx";
WebRequest tRequest;
tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
tRequest.Method = "post";
tRequest.ContentType = "application/json";
tRequest.Headers.Add(string.Format("Authorization: key={0}", SERVER_API_KEY));
tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
tRequest.ContentLength = byteArray.Length;
Stream dataStream = tRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse tResponse = tRequest.GetResponse();
dataStream = tResponse.GetResponseStream();
StreamReader tReader = new StreamReader(dataStream);
String sResponseFromServer = tReader.ReadToEnd();
tReader.Close();
dataStream.Close();
tResponse.Close();
}
catch (Exception)
{
throw;
}
}
Where: SERVER_API_KEY and SENDER_ID I got from in console.firebase.google.com/Project settings/Cloud Messaging
I tried to test the API that sends notifications to the device I get the error: {\"multicast_id\":7343900550378569449,\"success\":0,\"failure\":1,\"canonical_ids\":0, \"results\":[{\"error\":\"InvalidRegistration\"}]}
I referenced this article. However I want to use this code because it allows me to set the Notification link and icon. Is this an outdated notification code? I searched the forums, and didn't get any reasonable results. Looking forward to everyone's help.
I have an Email Razor page that accesses a custom method to send and email. All code seems to be correct. The problem I am having is accessing the "IFormFile files". I have tried adding the code to a controller as well as adding the IFormFile files to the custom method. I just can seem to find the right way to hande IFormFile. Below is the code that I currently have. What I am looking for is to see if someone can help me with the IFormFile portion. The information on IFormFile that I have found hasn't helped me so far as it's usually only partial information...I am very new to MVC and IFormFile, so help is greatly appreciated!
private async Task SendEmail()
{
try
{
// create email message
var email = new MimeMessage();
email.From.Add(MailboxAddress.Parse(sender));
email.To.Add(MailboxAddress.Parse(receiver));
email.Subject = emailsubject;
var multipart = new Multipart("mixed");
multipart.Add(new TextPart(TextFormat.Html) { Text = emailMessage });
foreach (var attachment in file)
{
var content = new MemoryStream();
attachment.CopyTo(content);
content.Position = 0;
var contentType = ContentType.Parse(attachment.ContentType);
var part = new MimePart(contentType.MimeType)
{
FileName = Path.GetFileName(attachment.FileName),
ContentTransferEncoding = ContentEncoding.Base64,
Content = new MimeContent(content),
};
multipart.Add(part);
}
email.Body = multipart;
//email.Body = new TextPart(TextFormat.Html) { Text = emailMessage};
// send email
using var smtp = new SmtpClient();
smtp.Connect(outgoingServer, outgoingPort, SecureSocketOptions.Auto);
smtp.Authenticate(userName, userPassword);
smtp.Send(email);
smtp.Disconnect(true);
}
catch (Exception ex)
{
NotificationService.Notify(NotificationSeverity.Error, "Send Email Error!", ex.Message, 7000);
}
}
I have a problem with getting profile image from Delve account. Here is the example of link which returns me photo when i put it into browser: https://orgname.sharepoint.com/_vti_bin/DelveApi.ashx/people/profileimage?userId=alias#org.com&size=L
Now I need to get this photo from code. I tried such way, that works perfect for external images not in Office365:
var credentials = new NetworkCredential("myemail", "password");
using (var handler = new HttpClientHandler { Credentials = credentials })
using (var client = new HttpClient(handler))
{
var bytes = await client.GetByteArrayAsync(url);
return Convert.ToBase64String(bytes);
}
But as responce I get html page with text like:
<H1>We can't sign you in</H1><p>Your browser is currently set to block cookies. You need to allow cookies to use this service.</p><p>Cookies are small text files stored on your computer that tell us when you're signed in. To learn how to allow cookies, check the online help in your web browser.</p>
I think it is related with Office365 Authorization, but I don`t know how to perform REST request to this url with my credentials...
Problem Solved, first we need to initialize SharePoint Context:
public ClientContext SetupSpContext()
{
// This builds the connection to the SP Online Server
var clientContext = new ClientContext(_sharePointCrmDocumentsSiteName);
var secureString = new SecureString();
foreach (var c in _sharePointCrmDocumentsPwd.ToCharArray()) secureString.AppendChar(c);
{
clientContext.Credentials = new SharePointOnlineCredentials(_sharePointCrmDocumentsLoginName, secureString);
}
var web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
return clientContext;
}
Then we can Get profile picture from Shrepoint using User email:
public string DownloadProfilePictureAsBase64(string email)
{
try
{
var pictureUrl = GetPictureUrl(email);
var fileInfo = File.OpenBinaryDirect(_sharePointContext, pictureUrl);
using (var memory = new MemoryStream())
{
var buffer = new byte[1000000];
int nread;
while ((nread = fileInfo.Stream.Read(buffer, 0, buffer.Length)) > 0)
{
memory.Write(buffer, 0, nread);
}
memory.Seek(0, SeekOrigin.Begin);
var buffer2 = new byte[memory.Length];
memory.Read(buffer2, 0, buffer2.Length);
return Convert.ToBase64String(buffer2);
}
}
catch (Exception ex)
{
Console.WriteLine($"Picture for user {email} can not be downloaded");
Console.WriteLine(ex.Message);
}
return null;
}
private string GetPictureUrl(string email)
{
string targetUser = $"i:0#.f|membership|{email}";
var peopleManager = new PeopleManager(_sharePointContext);
var personProperties = peopleManager.GetPropertiesFor(targetUser);
_sharePointContext.Load(personProperties, p => p.PictureUrl);
_sharePointContext.ExecuteQuery();
var pictureUri = new Uri(personProperties.PictureUrl);
var localPath = pictureUri.LocalPath.Replace("MThumb", "LThumb"); //Change size of the picture
return localPath;
}
You should Microsoft Graph to get a user's picture. https://graph.microsoft.com/v1.0/me/photo gets your metadata about the profile picture, and https://graph.microsoft.com/v1.0/me/photo/$value gets you the image. You need to use OAuth. See https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/profilephoto_get for more details.
Is it possible to send out an email with multiple email addresses specified in the "to" field? I have it working for single recipients, but can't figure out how to send to multiple, here is my current code for emailing a single user:
public static void sendCRMNotification(string userGuid, string emailSubject, string emailBody, string recipientType)
{
//Set up CRM service
crmService crmservice = GetCrmService();
// Create a FROM activity party for the email.
activityparty fromParty = new activityparty();
fromParty.partyid = new Lookup();
fromParty.partyid.type = EntityName.systemuser.ToString();
fromParty.partyid.Value = new Guid(/*guid of sending user*/);
//Create a TO activity party for email
activityparty toParty = new activityparty();
toParty.partyid = new Lookup();
toParty.partyid.type = EntityName.contact.ToString();
toParty.partyid.Value = new Guid(userGuid);
//Create a new email
email emailInstance = new email();
//set email parameters
emailInstance.from = new activityparty[] { fromParty };
emailInstance.to = new activityparty[] { toParty };
emailInstance.subject = emailSubject;
emailInstance.description = emailBody;
//Create a GUId for the email
Guid emailId = crmservice.Create(emailInstance);
//Create a SendEmailRequest
SendEmailRequest request = new SendEmailRequest();
request.EmailId = emailId;
request.IssueSend = true;
request.TrackingToken = "";
//Execute request
crmservice.Execute(request);
}
This is what I have done in the past. Create the array in the beginning before you set it to the email property.
activityparty[] toParty = new activityparty[2];
toParty[0] = new activityparty();
toParty[0].partyid = new Lookup(EntityName.contact.ToString(), userGuid);
toParty[1] = new activityparty();
toParty[1].partyid = new Lookup(EntityName.contact.ToString(), anotherUserGuid);
emailMessage.to = toParty;