I was trying to write an Email sending code for Windows Phone Universal App. This is the Code that I have written in my Event Handler:
Windows.ApplicationModel.Email.EmailMessage email = new Windows.ApplicationModel.Email.EmailMessage();
email.Subject = "Good morning";
email.Body = "Hello, how are you?";
var emailRecipient = new Windows.ApplicationModel.Email.EmailRecipient(email.Address);
email.To.Add(emailRecipient);
await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(email);
This code works for my Windows Phone 8.1 App. But it's not working in the Universal App. Shall I have to add any reference? Is there any way to make it work in the Universal app?
Thanks a lot. :)
In Windows Store App, Windows.ApplicationModel.Email namespace is not supported.
See EmailMessage class in MSDN.
You can send mail use mailto protocol, and use LaunchUriAsync method. like this:
await Launcher.LaunchUriAsync(
new Uri(
"mailto:someemail#somedomain.com?subject=SomeSubject&body=mail content"
));
In UWP development, a lot of codes still same with Windows Phone 8.1 /Windows Store App. As below shown send an email with attachment.
EmailMessage email = new EmailMessage();
email.To.Add(new EmailRecipient("test#developerpublish.com"));
email.Subject = "Blog pos`enter code here`t by #isenthil";
var file = await GetTextFile();
email.Attachments.Add(new EmailAttachment(file.Name, file));
await EmailManager.ShowComposeNewEmailAsync(email);
Related
I am using the Xero-node SDK to automatically create client invoices which works well.
At the end of the process, I would like to automatically email the client the invoice.
In the documentation it has the following example:
const xeroTenantId = 'YOUR_XERO_TENANT_ID';
const invoiceID = '00000000-0000-0000-0000-000000000000';
const requestEmpty: RequestEmpty = { };
try {
const response = await xero.accountingApi.emailInvoice(xeroTenantId, invoiceID, requestEmpty);
console.log(response.body || response.response.statusCode)
} catch (err) {
const error = JSON.stringify(err.response.body, null, 2)
console.log(`Status Code: ${err.response.statusCode} => ${error}`);
}
I have 2 questions:
The requestEmpty method does not work in javascript. Does anyone know the correct structure of requestEmpty?
I have used requestEmpty = { } but this throws an error => even though the system does actually send an email (probably a bug)
AND....
Is there a way for me to specify the email template that I would like the invoice to use (if I have specific templates setup in the web version)? Currently it seems to use the default Xero email template.
If you don't get an answer to your first query here, please can you raise it on the SDK page in Github and the Xero SDK team will look into this for you.
With regards to point 2, it is not possible to choose the email template when sending through the API, a basic template is used.
I would like to post a message to personal chat instead of group chat while message post from group chat how to achieve this ?.
Is there is any methods available related to this issue ?.
As the others have noted in this thread, you need to use something called "Proactive Messaging". I see you're using node.js though, so here is a better sample than the C# or Java people have posted already: https://github.com/pnp/teams-dev-samples/tree/main/samples/bot-proactive-messaging . I put both a dotnet as well as a node.js version in the sample, and there are some links at the bottom of the page to read more about the topic. Here is also a link to a video session where I talk more about the concept: https://www.youtube.com/watch?v=mM7-fYdcJhw&t=1398s
It is important to know that proactive messaging will only work if you have a "context" with the user already, which basically means they have to have installed your app already. It is possible to pre-install it on their behalf though. You need to use Graph to do this, and you can read more about it here: https://learn.microsoft.com/en-us/graph/api/userteamwork-post-installedapps?view=graph-rest-1.0&tabs=http .
You can post a proactive personal message to a user:
Please find below sample code:
Also, before running this code, make sure that the user has installed the bot app in the personal scope or is a member of a Team which has the bot installed.
Reference docs:
https://learn.microsoft.com/en-us/java/api/com.microsoft.cognitiveservices.speech.transcription.conversation.createconversationasync?view=azure-java-stable
using Microsoft.Bot.Builder;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;
using Microsoft.Bot.Schema.Teams;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Teams.Bot.Conversations
{
class Program
{
public static async Task Main(string[] args)
{
//Teams internal id
string teamInternalId = "19:96391bb270744e218c04dc8f571d3d8b#thread.skype";
//The Bot Service Url needs to be dynamically stored and fetched from the Team. Recommendation is to store the serviceUrl from the bot Payload and later re-use it to send proactive messages.
string serviceUrl = "https://smba.trafficmanager.net/emea/";
//the upn of the user who should recieve the personal message
string mentionUserPrincipalName = "user#tenant.onmicrosoft.com";
//Office 365/Azure AD tenant id for the
string tenantId = "<tenant-GUID>";
//From the Bot Channel Registration
string botClientID = "<client-id>";
string botClientSecret = "<client-secret>";
var connectorClient = new ConnectorClient(new Uri(serviceUrl), new MicrosoftAppCredentials(botClientID, botClientSecret));
var user = await ((Microsoft.Bot.Connector.Conversations)connectorClient.Conversations).GetConversationMemberAsync(mentionUserPrincipalName, teamInternalId, default);
var personalMessageActivity = MessageFactory.Text($"Personal message from the Bot!");
var conversationParameters = new ConversationParameters()
{
ChannelData = new TeamsChannelData
{
Tenant = new TenantInfo
{
Id = tenantId,
}
},
Members = new List<ChannelAccount>() { user }
};
var response = await connectorClient.Conversations.CreateConversationAsync(conversationParameters);
await connectorClient.Conversations.SendToConversationAsync(response.Id, personalMessageActivity);
}
}
}
I'm trying to use SendGrid to send an email from an Azure worker role every time there are certain exceptions, but I can't get the email to send. I am using SendGridMail version 6.1.0.0 and SendGrid.SmtpApi version 1.3.1.0 which I installed via nuget and .Net 4.5. I am currently debugging locally with plans to deploy to Azure if i can get the emails to successfully send.
SendGridMessage myMessage = new SendGridMessage();
List<String> recipients = new List<String> { #"John Doe <johnd#outlook.com>", #"Peter Howe <perterhowe#gmail.com>" };
myMessage.AddTo(recipients);
myMessage.From = new MailAddress("myemail#test.com");
myMessage.Subject = "Error in Update";
myMessage.Text = "TESTING 123";
string username = XXXXXX;
string password = XXXXXXX;
// Create credentials, specifying your user name and password.
var credentials = new NetworkCredential(username, password);
// Create an Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
await transportWeb.DeliverAsync(myMessage);
As far as I can see I'm not getting any errors except when I debug and look at myMessage the Header has an error.
When I tried initializing a new empty header (var header = new Header();) I noticed there were still errors on that
To = 'header.To' threw an exception of type 'System.ArgumentException' Message = "Bad key path!"
Does anyone know what this means? Or if this could be causing the emails not to send?
The answer to your other question actually uses SendGrid:
Alerts for exceptions in an Azure worker role
There are three globalvariables:
public const string SmtpServerHost = "smtp.sendgrid.net";
public const string SmtpServerUserName = "[useridfromsendgrid#azure.com]";
public const string SmtpServerPassword = "[password from sendgrid]";
You actually do not need to use the SDK, just setup the account in Azure portal, and save your creds in your project.
You can send emails locally, but if you are on a work network, the firewall may block the emails from being sent. The code I posted I placed in an email service in my namespace.
It has be deployed to Azure to work. It won't work locally.
I am developing a MVC 5 internet application, and am wishing to send an email using the SendGrid service when my application is deployed to Azure.
I have found some resource links, yet each different code implementation that I use, sends the email very slowly. I have chosen to use the code from this link: http://www.codeproject.com/Articles/762427/ASP-NET-Identity-Setting-Up-Account-Validation-and
Here is my code:
public class EmailService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
// Credentials:
var sendGridUserName = "myusername";
var sentFrom = "test#email.com";
var sendGridPassword = "mypassword";
// Configure the client:
var client =
new System.Net.Mail.SmtpClient("smtp.sendgrid.net", Convert.ToInt32(587));
client.Port = 587;
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
// Creatte the credentials:
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential(sendGridUserName, sendGridPassword);
client.EnableSsl = true;
client.Credentials = credentials;
// Create the message:
var mail =
new System.Net.Mail.MailMessage(sentFrom, message.Destination);
mail.Subject = message.Subject;
mail.Body = message.Body;
// Send:
return client.SendMailAsync(mail);
}
}
The email takes many minutes to send. Why is this? How fast should the email be sent on average, and do I need to optimize my code in any way? Also, rather than using SendGrid, is there a better resource to use that I should use?
Thanks in advance.
Somewhere on Sendgrid documentation (can't find it now unfortunately) I have seen recommendation that if you use their REST API endpoints instead of SMPT, the emails will arrive quicker. And Sendgrid provides C# library to use their API. Give it a go.
It's possible SendGrid is deferring or delaying your sends. Is there any defer or delay activity in your SendGrid dashboard?
You can also connect to the SendGrid Webhook Events to see exactly what's going on with your emails.
i just came up with a new problem but the same context azure. now i am trying to implement Multilinqual(localized) push notifications so i am following this localized push notification so this link inculde lot of work of making categories i just wanted to omit them so i am trying to use direct code for subscribing the toast notification on the basis of tag given in Bachend clien app that generate toast notification...here is Backend client app code..
NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("Endpoint=sb://samplenotificationhub-ns.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=", "samplenotificationhub");
var notification = new Dictionary<string, string>() {
{"News_English", "World News in English!"},
{"News_French", "World News in French!"},
{"News_Mandarin", "World News in Mandarin!"}};
await hub.SendTemplateNotificationAsync(notification, "World");
first i tried it on my previously working sample app that can receive Push notification on the basis of tags also so i just tried to update its code to get template based toaste notification but unfortunately i am not getting anything..here is the code..
private void AcquirePushChannel()
{
CurrentChannel = HttpNotificationChannel.Find("mychannel");
if (CurrentChannel == null)
{
CurrentChannel = new HttpNotificationChannel("mychannel");
CurrentChannel.Open();
CurrentChannel.BindToShellToast();
CurrentChannel.BindToShellTile();
}
CurrentChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
{
var tags = new HashSet<string>();
tags.Add("World");
var hub = new NotificationHub("samplenotificationhub", "Endpoint=sb://samplenotificationhub-ns.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=");
var template = String.Format(#"<toast><visual><binding template=""ToastText01""><text id=""1"">$(News_English)</text></binding></visual></toast>");
await hub.RegisterTemplateAsync(args.ChannelUri.ToString(),template,"hello", tags);
// await hub.RegisterNativeAsync(args.ChannelUri.ToString(),tags);
});
}
so if you know anything about it..please guide me any kind of help or suggetion is appreciated..
Hello Friends I again able to solve my problem so the mistake i am doing here is i am following the link blindly as it is for Windows store apps and i wanted to implemented the same for windows phone 8 so what i am doing wrong is using the same Tamplate that is used in windows store apps for windows phone 8 too. so what i understand is this if wanted to target the multiple platforms from a notification hub then your client app that send the toast notification has the same notification for all but all your platform will handle it differently Like for windows 8 the tamplate i am using will work but windows phone this template will work.
string toast = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Toast>" +
"<wp:Text1>Hello Windows phone</wp:Text1>" +
"</wp:Toast> " +
"</wp:Notification>";
so different platform will have different platform.hope it help somebody else too.