MimeKit | NET MIME creation and parser library | Parser library
kandi X-RAY | MimeKit Summary
kandi X-RAY | MimeKit Summary
MimeKit is a C# library which may be used for the creation and parsing of messages using the Multipurpose Internet Mail Extension (MIME), as defined by numerous IETF specifications.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of MimeKit
MimeKit Key Features
MimeKit Examples and Code Snippets
Community Discussions
Trending Discussions on MimeKit
QUESTION
Let me start by saying there may be a better way to go about this so by all means feel free to suggest a different approach.
What I am trying to do is send an email from a template in a Blazor server side application. The email library (MailKit) needs the body to be rendered as a string as I understand it.
Of course I want this to be a template so my thought process was to have a cshtml page with a model. Render it with the model passed in and take the output string and use that for the body.
So my mailing code would look like this:
...ANSWER
Answered 2021-Sep-11 at 18:37You're in luck - I had the same problem a few months ago when trying to use RazorLight (a similar .cshtml
templater) and ran into too many problems.
I realised that .razor
files are so much better suited to this use case than .cshtml
files since they compile to plain C# classes - except nothing was available to render them. So I wrote BlazorTemplater which does exactly that.
- Install the Blazor Templater Nuget Package
- Convert your
.cshtml
file to.razor
(e.g.ConfirmUser.razor
) and switch from importing a Model to using .razor parameters, e.g.
QUESTION
I ama able to sent SMTP emails using MailKit & MimeKit and outlook is the client tool receiving these mails. Below code has been used and my Inbox has emails received.
...ANSWER
Answered 2022-Mar-11 at 14:24Before I explain how to save the message in your Sent IMAP folder, I first want to bring attention to a few things.
smtp.Timeout = 10000;
It's probably best to not override the default timeout (which I believe is 120,000. 10000 is 10 seconds).- You currently have a mix of sync and async calls to the SmtpClient. You should pick sync or async and stick with it (at least if it's all within the same method).
Okay, now on to your question.
QUESTION
In VS-2022, .Net 6, Blazor WASM, C#, MailKit 3.1.1.
I am getting this error "The type initializer for 'MailKit.Net.Smtp.SmtpClient' threw an exception"
on this source-code when trying to instantiate SmtpClient:
// NEW INFORMATION: InnerExeption is: 'System.PlatformNotSupportedException: System.Net.NetworkInformation is not supported on this platform. at System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties() at MailKit.Net.Smtp.SmtpClient..cctor()' – So now, MS recommends MailKit and then MailKit does not support .Net 6. What gives?
from MSDN "SmtpClient Class"
Remarks
The SmtpClient class is used to send email to an SMTP server for delivery. The SMTP protocol is defined in RFC 2821, which is available at https://www.ietf.org.
Important
We don't recommend that you use the SmtpClient class for new development because SmtpClient doesn't support many modern protocols. Use MailKit or other libraries instead. For more information, see SmtpClient shouldn't be used on GitHub.
Did .Net 6 interfere with MailKit working? Your comments are welcome...Thanks
...ANSWER
Answered 2022-Mar-08 at 17:08Since you are using WASM (aka Blazor WebAssembly), you will probably be not able to use an SMTP client client-side.
To quote an answer to a similar issue on GitHub:
It is unlikely than an SMTP client is going to work in Blazor WebAssembly. Ultimately Blazor is subject to the same restrictions that any other application running in the browser.
That means you can't create TCP or UDP connections since browsers don't allow that.
You'll likely need to do this from an endpoint on a server through a Rest API.
This is what I would actually do, too:
- Create a server-side ASP.NET Core Web API endpoint.
- Protect the API endpoint with some API key to not expose it publicly.
- Pass the related data from your WASM to that Web API.
- Send the actual email message via MailKit from that server-side API.
QUESTION
I would like to pass the To Mailbox Address as a parameter with multiple addresses using MimeKit to send a message.
If I edit the controller action to include a string with 2 email addresses:
...ANSWER
Answered 2022-Feb-17 at 05:35Please try to use string[] eMailTo
, it should be useful to you.
QUESTION
I'm working with mimekit to encrypt and decrypt mime messages and send them via Graph API, the encryption seems to work well but the receiver of the message can't decrypt the message via it's Outlook client. In other encrypted mails the reciever generated he can see a padlock in it's Outlook client and then install the certificate and then decrypt the message, but when I send the message via Graph API that padlock isn't there.
Furthermore, when I try to get the same message I already sent encrypted and then decrypt it I get the following error:
...ANSWER
Answered 2022-Feb-14 at 18:04Try this:
QUESTION
I'm working with mimekit to encrypt and decrypt mime messages and I'm encountering this error everytime I try to decrypt a message:
Unexpected object reading content. BouncyCastle.Crypto at Org.BouncyCastle.Cms.CmsContentInfoParser..ctor(Stream data) in //crypto/src/cms/CMSContentInfoParser.cs:line 35 at Org.BouncyCastle.Cms.CmsEnvelopedDataParser..ctor(Stream envelopedData) in //crypto/src/cms/CMSEnvelopedDataParser.cs:line 65 at MimeKit.Cryptography.BouncyCastleSecureMimeContext.d__50.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at PasarelaLibrary.Bases.GraphService.BaseGraphPasarela.d__11.MoveNext() in C:\Dev\Euroval\PasarelaAceuro\PasarelaLibrary\Bases\GraphService\BaseGraphPasarela.cs:line 302 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at PasarelaLibrary.Bases.GraphService.BaseGraphPasarela.d__9.MoveNext() in C:\Dev\Euroval\PasarelaAceuro\PasarelaLibrary\Bases\GraphService\BaseGraphPasarela.cs:line 237
Inner exception
Unable to cast object of type 'Org.BouncyCastle.Asn1.DerApplicationSpecific' to type 'Org.BouncyCastle.Asn1.Asn1SequenceParser'. at Org.BouncyCastle.Cms.CmsContentInfoParser..ctor(Stream data) in /_/crypto/src/cms/CMSContentInfoParser.cs:line 27
the problem is I'm just trying to encrypt and decrypt a message to test the library and the flow of the application and I'm getting this error. Above you can find the code I'm using. I'm using a x509Certificate with a password that I'm importing in the TemporarySecureMimeContext.
...ANSWER
Answered 2022-Feb-10 at 15:43You're using it wrong :-)
You are trying to decrypt a MIME message stream. You can't do that.
The SecureMimeContext.Decrypt() and DecryptAsync() methods expect the encrypted content of the MIME message.
If your goal is to load the MimeMessage and decrypt it, you would change your code to this:
QUESTION
Update: I've updated this a bit to remove the reference to the error. @michal-diviš gave the correction solution to that. However, my larger issue still remains.
I'm new to Xamarin and trying to learn by making a simple email client. I'm trying to set a property on a ContentPage I have created.
The SetupThe MainPage simply has a grid with two columns; the left side features an CollectionView of the inbox, the right side is my custom ContentPage MessageDisplayView
. When an email is clicked in the CollectionView, the CurrentMessage
property on the MainPageViewModel
is updated to the selected item.
I'm trying to bind the property MessageDisplayView.Message
to the MainPageViewModel.CurrentMessage
property, but the contentpage never updates. I've tried with and without BindableProperty, as well as other ideas found while searching Google and Stackoverflow.
How do I handle setting and updating a property that I would like to live with the ContentPage?
The CodeMainPage.xaml
...ANSWER
Answered 2022-Feb-03 at 14:07It's the BindableProperty
definition!
You have (in the MessageDisplayView.xaml.cs):
QUESTION
I am currently working on a microservice that runs on DotNet6 and is using MailKit 3.1.0. I have the following code snippet:
...ANSWER
Answered 2022-Jan-26 at 16:35You need to properly quote the name if it contains @
symbols or .
.
Those are special characters that are required to be quoted by the email specifications.
In other words, the correct string would be:
QUESTION
How do I in Mimekit send an email having the html body base64 encoded?
In code I first create the entire body as a MimeEnitity including attachments using the BodyBuilder. Then I create the MimeMessage to be sent having the body.
...ANSWER
Answered 2022-Jan-13 at 21:47The first thing you'll need to do is to locate the HTML body part.
A quick hack might look something like this:
QUESTION
I am writing a frontend/backend application. The frontend is an Angular 13 application. The backend is a combination backend API and administration web site. The backend has:
- Local Identity (including Identity scaffolding),
- Web API (for Angular frontend using Swagger bearer tokens),
- MVC view/controllers for side table administration.
The frontend needs to access API services. Login returns a token. The token is used to access the various services to maintain the application tables.
The backend .net 5 Core website reads and writes to a local SQL Server database. The database contains the Identity tables. The backend is also used to maintain the Identity tables using the scaffolding Razor pages. The backend maintains (basic CRUD) for a number of administrative tables. So, a user or an administrator logons via the scaffolding logon form using the same logon account that is used for the Angular frontend.
The problem is the login via PasswordSignInAsync is successful but User.Identity.IsAuthenticated is false. I use User.Identity in lots of places for name, roles and IsAuthenticated. I got a sense that User.Identity is supposed to happen automatically when using cookie authentication scheme. I added dual schemes, but that has not solved the problem. I have read through a number of questions per PasswordSignInAsync not working, but none seemed to help. The things I tried to solve the problem may have adversely affecting the outcome. I have read the source code of CheckPasswordSignInAsync and I do not see any setting of User.Identity. Not knowing what to do to get beyond this issue.
Please feel free to ask for any clarifications.
I’m showing my complete Startup.cs.
...ANSWER
Answered 2021-Dec-24 at 16:35After starting from ground zero, I feel I found the problem. I am now getting logon via Swagger API service (Angular 13) and the logon.cshtml Identity Razor scaffolding page.
When one properly adds the Identity scaffolding, one needs to change/review the IdentityHostingStartup.cs file. My updated IdentityHostingStartup is as follows:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install MimeKit
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page