SQLite is not available error on pkcs7.Decrypt() of MimeKit - c#

I've encountered an error SQLite is not available while decrypting a mime message after executing pkcs7.Decrypt(). Please see my block of code below:
public MimeEntity decryptMessage(MimeMessage message)
{
// Putting the value of message.body to a string for checking only
using (var memory = new MemoryStream())
{
responseString.Body.WriteTo(memory);
string bodystring = Encoding.UTF8.GetString(memory.ToArray());
}
var pkcs7 = message.Body as ApplicationPkcs7Mime;
if (pkcs7 != null && pkcs7.SecureMimeType == SecureMimeType.EnvelopedData)
{
// the top-level MIME part of the message is encrypted using S/MIME
return pkcs7.Decrypt();
}
else
{
// the top-level MIME part is not encrypted
return message.Body;
}
}
I've tried to put the value of message.Body into a variable and check its value but it seems that it doesn't have any problem:
Content-Type: application/pkcs7-mime; smime-type=enveloped-data;
name=smime.p7m
Content-Disposition: attachment; filename=smime.p7m
Content-Transfer-Encoding: base64
MIAGCSqGSIb3DQEHA6CAMIACAQAxggFAMIIBPAIBADAkMBYxFDASBgNVBAMTC1NpbmFwdElR
IENBAgoeg+bBAAAAAAAMMA0GCSqGSIb3DQEBAQUABIIBAFDuM37IZePCJIuiDkwG7qV3pAJs
+e+8h2yNZJ7s4pQqV+DNUC6n+YzHVuTKLN/J4g2KObx879al6hVu2I7338fws/i9RxHmQj8P
Rfld43KTULMIsAh71ApVMF0AKyDvtWcpijSL9oVf4o6kO7rhIT2GvFO3yaMztvvtWbl5LaVw
9bDuSxA2LwVlx8kH9rXOewrH3+pchLqcKNT498WZxdwuWvwQnANUR78izIzHLgeToRIU2VFz
/X58Fzj/R2s+seKtL2J76lvsU4ubzNJj0IgRVKV1n2cx1hgmJ4qXziOdtCtmj16y71AnIILi
n2LPe1LxB8m56ekgLC/s2F+kPdowgAYJKoZIhvcNAQcBMBQGCCqGSIb3DQMHBAjfU7YPkiQm
RqCABIID6KdFKz3Q624R1EdUQEz2qYb8rTQ1OBcs34ubCNcMkKru42vM0w1QSD9Cx81jXEDa
jTISQv6iQWUBk2luEzupnwIY6Kk0qvlhTqOTL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Fqb5k
MFZumMZHqvFDtRrOC4cjvDoWamUbIipSoFMStO0Qxkx9rPZophbsQoq0v6DXQz6N752kJ/X8
vSkTDeZ9u6RfzP8SBWZjc8er9VCg8m8PHMoF4FYdoh8o2/EOn29DL4vuzugJ5OHVFpt+s4QC
XNmB6WXsp9VmLuS/Q3fGoC1vvzyEC8fOAGXVl5iFLq5xYna4xSjahcozM+pYo4dDDicjFdN+
tcRZ4WBk9GbOTXeevBRZrA1wU0gOxUtOkqwBjwGRbtLgSkJbCiIakt1Qk/pj8xutA8LUuOl4
dDeqjLgTIMDxPnWnc24stCac+llwUkqC+mWZb8ygX/PfKNO2ydpTUNp9ZhkClMzeQIsMeSOr
OHJl0LO1bp9ZuIX+wJvrB2ZdmYxdwVkpfkm3JkfM8ZdBzX7kzZxMASk+pgMHQ2qzNype5nwD
H/7tLxqTlRKIf1xX6QQ49RjyqIf2IT/hByCM3SCL0URdbZyQYzf71vCRd9RpLTKOvP/hzIFc
1t7wTLW53B/TF88W1Ufa9oUAAAAAAAAAAAAA
So now I can't understand why the error says SQLite is not available despite that I'm not using any database connection on this one. I'm new to using MimeKit. If anyone knows how can I do this it will be a great help.

Related

how to check if user already exists in firebase c#

I built a login/register system, and I want that when you create a username it checks if email exists, it works fine and it shows the message box "Email exists", but when it is a new user and there is no email that exists, it crashes.
Here is the exception message:
(System.NullReferenceException) Message=The object reference was not set to an object instance
Code:
FirebaseResponse response = await client.GetTaskAsync("Information/" + Emailtextbox.TextName);
Data result = response.ResultAs<Data>();
if (Emailtextbox.TextName == result.Email)
{
MessageBox.Show("Email exists");
} else
{
var data = new Data
{
Email = Emailtextbox.TextName,
Fullname = Fullnametextbox.TextName,
Password = EncryptSHA.GetShaData(PasswordTextbox.TextName)
}
};
Updating this based on the screenshot of the error as well as the information provided in the following comments.
It looks like your error has to do with what's being returned from your client.GetTaskAsync("Information/" + Emailtextbox.Textname); call.
My recommendation would be to try and understand what it is you're receiving from that call (what's stored in your response object). With the latest screenshot I see that the Body is null, and that might be part of the problem. Try expanding what you see in the Response object in your response and see if you're even receiving any kind of data you can use and go from there.

Body or Message Contains method using MailKit

I'm using MailKit for received messages via Imap.
Now I need a search-logic for the software and I got a some troubles.
For ex, I using:
var query = SearchQuery.BodyContains("SomeTextfromEmail");
( or var query = SearchQuery.MessageContains("SomeTextfromEmail"); )
foreach (UniqueId uid in imapfolder.Search(query)){
//some logic
}
So, I can't get messages with text contains on it with Search filter.
I'm downloaded message ( message.WriteTo(string.Format(#"C:{0}.eml", uid)); )
and see the message content. Text of message in a base-64 format.
How do it correctly? I need decode message text from base64?
Problem are here:
var query = SearchQuery.BodyContains("Iphone").And(SearchQuery.All); //this construction find messages in folder
foreach (var uid in imapfolder.Search(query))
{
Console.WriteLine(message.From + " : " + uid.ToString());
}
var query = SearchQuery.BodyContains("Received from Iphone").And(SearchQuery.All); //this construction can't find message in folder
foreach (var uid in imapfolder.Search(query))
{
Console.WriteLine(message.From + " : " + uid.ToString());
}
Your question is a jumbled mess of confusion (your question starts out saying you are trying to figure out how to search and then you end with asking how to base64 decode the raw message that you saved to a file) so I have no idea exactly what you want to know.
If all you want is the decoded text body, you can do this:
var message = imapfolder.GetMessage (uid);
var text = message.TextBody;
This will be the decoded text string (either base64 decoded or quoted-printable decoded if it needs to be).
The MimeKit README and FAQ are both full of useful information on the basics of how to use them. I would highly recommend reading them as they may be helpful.
Update:
Based on the comment added to my answer, it sounds like what you want to do is this?
var matched = new UniqueIdSet ();
foreach (var uid in folder.Search (SearchQuery.BodyContains ("iPhone"))) {
var message = folder.GetMessage (uid);
var body = message.TextBody;
if (body != null && body.Contains ("Received from iPhone"))
matched.Add (uid);
}

Gmail api read/decode message c#

I'm using the new gmail api in c# application, and I want to know how I can read the body of a message after getting the message with the get method? Can i get a MailMessage object from the "Raw" property of the message (to create a Raw from a mailMessage i use this, is there a way to convert it back?), or i need to use the "Payload" property?
This is my code: (the ListMessages and the GetMessage methods are from the
API Reference on google's site)
List<Message> msgList = ListMessages(gs, "me", "is:unread");
string id = msgList[0].Id;
Message msg = GetMessage(gs, "me", id);
Now what?
Please help.
Thanks.
From the API, your Message (1) has a Payload property of type MessagePart (2). MessagePart has a Body property of type MessagePartBody (3) which (finally) has a string Data property.
Data is the content of the message, so (using your example code) to get the message you would do something like:
msg.Payload.Body.Data
From there, how you use it is up to you, although you have to be aware that there may or may not be HTML in that value. From the API reference, we also see this for the Parts property of the Payload:
For non- container MIME message part types, such as text/plain, this
field is empty
So you could make the assumption that if msg.Payload.Parts contains no elements then it is a plain-text message.
The Gmail API is not super easy to use. They really leave a lot to the user to just figure out.
You're going to need to use recursion to get the correct structure and do some decoding of the message. The structure of the JSON is going to be very different depending on the format of the message, if there are attachments and the sending client.
This guide goes over exactly how to handle extracting the HTML and Plain text versions of the body.
Here part of the code from the guide that shows how to extract the body parts:
public static void ExtractMessagePart(MessagePart part, ref EmailMessageModel message)
{
if (part == null)
return;
var contentDisposition = part.Headers?.FirstOrDefault(h => h.Name == "Content-Disposition");
if (contentDisposition != null && (contentDisposition.Value.StartsWith("attachment") || contentDisposition.Value == "inline"))
{
message.Attachments.Add(new DragnetTech.EventProcessors.Email.EmailMessageModel.Attachment
{
AttachmentId = part.Body.AttachmentId,
Filename = part.Filename,
ContentID = contentDisposition.Value.StartsWith("inline") || part.Headers?.FirstOrDefault(h => h.Name == "Content-ID") != null ? Utils.UnescapeUnicodeCharacters(part.Headers.FirstOrDefault(h => h.Name == "Content-ID")?.Value) : null,
Size = part.Body.Size ?? 0,
ExchangeID = part.Body.AttachmentId,
Data = part.Body.Data,
ContentType = part.Headers?.FirstOrDefault(h => h.Name == "Content-Type")?.Value
});
}
else
{
if (part.MimeType == "text/plain")
{
message.Body = DecodeSection(part.Headers?.FirstOrDefault(h => h.Name == "Content-Transfer-Encoding")?.Value, part.Body?.Data);
message.IsHtml = false;
}
else if (part.MimeType == "text/html")
{
message.Body = DecodeSection(part.Headers?.FirstOrDefault(h => h.Name == "Content-Transfer-Encoding")?.Value, part.Body?.Data);
message.IsHtml = true;
}
}
if (part.Parts != null)
{
foreach (var np in part.Parts)
{
ExtractMessagePart(np, ref message);
}
}
}

How do you send an RichText Document as the body of an e-mail programatically using SmtpClient with .net

I am writing a WPF .net app to send an e-mail to several people.
I've got the program working so that it sends plain text e-mails using the code below:
private void OnSendEmails(object sender, RoutedEventArgs e)
{
using (SmtpClient smtpClient = new SmtpClient("<mySMTPserver>", <somePort>))
{
smtpClient.Timeout = 10000;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential("<myusername>", "<mypassword");
foreach (string address in Addresses)
{
try
{
Console.Out.WriteLine("Sending e-mail to: {0}", address);
smtpClient.Send(Sender, address, Subject, Body);
Console.Out.WriteLine("Sent e-mail to: {0}", address);
}
catch (Exception ex)
{
Console.Out.WriteLine("Exception thrown while sending to : {0}\r\n\r\n{1}", address, ex);
}
Console.Out.WriteLine("Sleeping");
Thread.Sleep(Seconds * 1000);
Console.Out.WriteLine("Done Sleeping");
}
}
}
I would like to send several e-mails out to a select group of people to advertise an app that I wrote. However, I want to send them something other than plain text. I can populate a RichTextBox with the content I wish to send, however, I don't know how to send it since SmtpClient just takes a 'string' to represent the body of the e-mail.
So the question is, how do I send the RichTextBox.Document as the Body of my e-mail using .net and SmptClient?
The document itself will contain images, text, and some links that are associated with icons.
try to create an object of type MailMessage:
var msg = new MailMessage(...);
then you can set this property:
msg.IsBodyHtml = true;
and the message body will be rendered in HTML format.
I am not totally sure the RichTextBox would pass HTML or probably RTF which is slightly different, it could be you should convert RTF into HTML with an helper method before assigning the content to msg.Body.

Send already generated MHTML using CDOSYS through C#?

I have a ready generated MHTML as a byte array (from Aspose.Words) and would like to send it as an email. I'm trying to do this through CDOSYS, though am open to other suggestions. For now though I have the following:
CDO.Message oMsg = new CDO.Message();
CDO.IConfiguration iConfg = oMsg.Configuration;
Fields oFields = iConfg.Fields;
// Set configuration.
Field oField = oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
oField.Value = CDO.CdoSendUsing.cdoSendUsingPort;
oField = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
oField.Value = SmtpClient.Host;
oField = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
oField.Value = SmtpClient.Port;
oFields.Update();
//oMsg.CreateMHTMLBody("http://www.microsoft.com", CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");
// NEED MAGIC HERE :)
oMsg.Subject = warning.Subject; // string
oMsg.From = "system#example.com";
oMsg.To = warning.EmailAddress;
oMsg.Send();
In this snippet, the warning variable has a Body property which is a byte[]. Where it says "NEED MAGIC HERE" in the code above I want to use this byte[] to set the body of the CDO Message.
I have tried the following, which unsurprisingly doesn't work:
oMsg.HTMLBody = System.Text.Encoding.ASCII.GetString(warning.Body);
Anybody have any ideas how I can achieve what I want with CDOSYS or something else?
Please don't use CDO, it dates from an era when computers still used smoke signals to exchange emails. System.Net.Mail contains everything you need, MailMessage is your friend. Note its IsBodyHtml property.
It is possible via CDO.Message (it is necessary add to project references COM library "Microsoft CDO for Windows 2000 Library"):
protected bool SendEmail(string emailFrom, string emailTo, string subject, string MHTmessage)
{
string smtpAddress = "smtp.email.com";
try
{
CDO.Message oMessage = new CDO.Message();
// set message
ADODB.Stream oStream = new ADODB.Stream();
oStream.Charset = "ascii";
oStream.Open();
oStream.WriteText(MHTmessage);
oMessage.DataSource.OpenObject(oStream, "_Stream");
// set configuration
ADODB.Fields oFields = oMessage.Configuration.Fields;
oFields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value = CDO.CdoSendUsing.cdoSendUsingPort;
oFields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value = smtpAddress;
oFields.Update();
// set other values
oMessage.MimeFormatted = true;
oMessage.Subject = subject;
oMessage.Sender = emailFrom;
oMessage.To = emailTo;
oMessage.Send();
}
catch (Exception ex)
{
// something wrong
}
}

Categories