Blazor MailKit bind values to the message - c#

I have a Blazor server app and I use Mailkit to send emails. Using a model I bind and send the email to the given address.
I have the following code that i use to send emails:
email.To.Add(MailboxAddress.Parse(model.ToEmail));
email.Subject = "EEXI Calculation Results";
email.Body = new TextPart(TextFormat.Html) { Text = "Full Name" };
Similarly how I bind the email address using:
email.To.Add(MailboxAddress.Parse(model.ToEmail));
I would like to bind other values from the inputs and show both text
email.Body = new TextPart(TextFormat.Html) { Text = "Full Name:",model.name};

That's what email templates are used for, there are many ways to create and use them. Here are some useful links:
Custom (simple) string template:
Create email templates in code... it's very basic, but sometimes that's all you need.
public string NewUserEmailTemplate(User user, string confirmationUrl){
return $"Welcome {user.FirstName} {user.LastName}! You are now a registered user. Please click the following url to confirm your account: {confirmationUrl}";
}
Razor page .cshtml email template
The more advanced and better way of doing email templates. Here's a link to a tutorial:
https://scottsauber.com/2018/07/07/walkthrough-creating-an-html-email-template-with-razor-and-razor-class-libraries-and-rendering-it-from-a-net-standard-class-library/

Related

SmtpClient and MailMessage - How to format for anchor tags?

I have an application that requires a user confirm their email upon registering, so I've created some functionality to send the user an email, with a link, where they can click on the link and then confirm their email.
In order to do this I'm using both MailMessage and SmtpClient classes to send the email.
Currently, my code is thus:
public ActionResult Send() {
MailMessage email = new MailMessage {
Subject = "Confirm Email",
Body = "<a href='http://www.google.com'>Google</a>",
IsBodyHtml = true
};
SmtpClient smtp = new SmtpClient();
smtp.Send(email);
return RedirectToAction("Index", "Email");
}
Now upon researching I found that the IsBodyHtml flag will help if I'm trying to send an email that has HTML contained within, although upon testing, the emails I'm receiving are not formatting anchor tags properly.
Any idea what I may be doing wrong, or how differently I can go about formatting my message body?
Thanks!
So, I made a goof here. Seems that the messages I was trying to send myself were going to Outlook's Junk Mail folder, which strips out the href value and displays it in the e-mail.
If I right click on the email and select Display HTML then the link displays as expected.
Oops!

Button in Email click to create new email with content

Introdution
I am currently working a system develop with C#.
The system is about request approval.
When a request made, system will send email to user ask for response.
User's response will as simple as approve, reject or request update.
Question/Problem
Is it possible to have a button (approve or reject) in email content which allow user to response to system with only one click but without open browser?
Or, Is it possible to create button in email content which enable user to click to create new email with pre-set subject and recipient like following:
subject: request id - 123 - action - approve
to: response#system.com
as response email for user to send.
Then system can then recognize the email received and perform required back-end process.
Research Done
Research 1
What I currently found was outlook appointment email.
it done like second solution create new email with content for user send a response.
But, it only have options accept, decline and tentative.
And, I am not sure is blackberry support it like outlook.
The following is the blog found to create appointment email:
http://chuckdotnet.blogspot.my/2007/10/send-outlook-meeting-requests-with.html
Research 2
The following website teach you how to create hyperlink in email content which can create new email with pre-populate subject, body, and recipient
https://community.articulate.com/discussions/building-better-courses/hyperlink-to-create-an-already-written-email
However, No test had perform in blackberry yet.
Appreciate for any suggestion from you guys and I willing to try.
Is it possible to sent an email with button which can click to create
email with some pre-set content?
Yes, this is possible, see the System.Net.Mail code in the .NET framework.
https://msdn.microsoft.com/en-us/library/system.net.mail(v=vs.110).aspx
You can also see this StackOverflow question about how this is used.
Send e-mail via SMTP using C#
MailMessage mail = new MailMessage("you#yourcompany.com", "user#hotmail.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);
Finally, your code should fire a serverside post on button click to have the server take care of sending the email. If data needs to be posted to the server, you may want to consider putting this data in a form input, which will post to your controller. You can then take that data and build the email with the example I provided in the links.

How to send an url in an email in a wp8 app

Is there a way to send a http link in a wp8 app? I'm using
EmailComposeTask emailComposeTask = new EmailComposeTask();
but whenever I include an http link in the body of my email, it just appears as regular text.
My http link is included in a default string, so it would kind of make sense, but I assumed that the email app receving the email would just detected the http://... and automatically converted it a link but that's not the case.
Should I include the http link within a specific tag??
Any ideas?
Thanks
You Would see link as normal Text in Body when Composing but in mail it would be seen highlighted as link
Try this :
EmailComposeTask task = new EmailComposeTask();
task.To = "Set Email here";
task.Subject = "Subject goes here";
task.Body = "Your Mesage goes here \n http://www.google.com";
task.Show();
I have attached Screen Capture of inbox.
When you called EmailComposeTask, It will show an mail edit page.
In this page, the http link can't be shown.
But when you send it, in the Sent folder, the mail can show http link.
And in the receiver's Inbox, it also can be shown.

Create Outlook Email in C# with anchor tag in body that has a target

My team and I have a very specific and frustrating issue. We have an MVC4 web application that many people utilized within a company (no external exposure). Some of our processes generate emails to other employees with links back to the application.
For example, there may be some activity that one employee sees and wants to attend. They can can an email to the other employee saying they would like to attend.
In these emails, we put an anchor tag in with the link back to our application and some query string stuff to help direct it to the right page.
All of that works wonderfully. Now, the problem is, we want the link (from the email) to load in an existing window with the application, if it exists. Normally, I believe, this would be done with setting the target attribute in the anchor tag, but that doesn't work, it just opens in a new tab.
This is what the anchor tag source from the email looks like (i've changed some text so that it hides company related info):
Please <a target="appMain" href='http://domain/app/controller.aspx/view?
keyname=querystringparam1&params={"prop1":val,"prop2":va;}'>
click here</a> to approve and go to app
this is our smtp function to send the mail:
public void SendMail(EmailContent emailContent, string mailConfigurationPath)
{
var toRecipients = string.Join(",", emailContent.ToList);
var mailMessage = new MailMessage(emailContent.From, toRecipients)
{
IsBodyHtml = emailContent.IsBodyHtml,
Body = emailContent.Body,
Subject = emailContent.Subject
};
var smtpClient = new SmtpClient
{
DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory,
PickupDirectoryLocation = mailConfigurationPath
};
smtpClient.Send(mailMessage);
}
Is what I'm trying to achieve even possible? It seems pretty straight forward, maybe I'm just going about it the wrong way. Would love some help or even some "crazy" ideas.
This is not possible, because it creates a vulnerability in the email program itself...
http://thenextweb.com/insider/2013/01/07/yahoo-mail-users-hit-by-widespread-hacking-xss-exploit-seemingly-to-blame/
Also, it goes against all the normal user interface guidelines for email programs. Users don't expect an email to transform into an app. They are very familiar with clicking on links in emails though, so you wouldn't want that action to do something weird.

Add Email address in to field of Email App using share contract?

I am creating a sample Win8 app and using share contract I am trying to share HTML Content. When the user select email app from the share application option I want to set email address in TO field. How can I do so? Following is my code written to share HTML content:
Code:
DataPackage requestData = request.Data;
requestData.Properties.Title = this.PageViewModel.JobInformationDetail.JobNumber;
requestData.Properties.Description = this.PageViewModel.JobInformationDetail.CustomerSignatureName;
//requestData.SetText("Sample Text");
StorageFile signatureStream = await GetInkManagerStream();
requestData.SetHtmlFormat(Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.CreateHtmlFormat(this.GetMailDescription()));
Following images shows where to set the email address in To field:
You can't do that. We'll have a solution to this until WinRT come up with a standard email DataPackage format to StandardDataFormats and support it in the email app.
I think Microsoft's default Mail should be upgraded. It's entirely depend upon sharing target app to show particular data to particular place. DataPackage's Title property is set as subject and Description property is set as mail body but there's no provsion for to email(s).
If sharing experience is best one then user will user default Mail app otherwise they will go for another mail apps.

Categories

Resources