smiley22 / s22.mail Goto Github PK
View Code? Open in Web Editor NEWA .NET assembly providing serialization and other extensions for the MailMessage class
License: MIT License
A .NET assembly providing serialization and other extensions for the MailMessage class
License: MIT License
@smiley22: It is possible to move this project (and other) in an org to improve the code, etc.?
Hi,
Where can i download S22.Mail.dll file. I need to store Message attachment into local hard drive.. Is there any work around for achieving this?
When you try to serialize the object with not with MemoryStream but with Json.NET
"JsonConvert.SerializeObject((SerializableMailMessage)message, Formatting.Indented);"
you receive this error:
Newtonsoft.Json.JsonSerializationException: 'Error getting value from 'ReadTimeout' on 'System.IO.MemoryStream'.'
It's possible to avoid this problem in the library or we need to act on Json.NET library?
Replace line 17 from SerializableLinkedResources.cs
before: return null;
after: return r;
In MailMessage.cs when an attachment is saved then subsequently recreated it appears that the original attachment name is lost and a new random string is generated in it's place.
To fix this I changed line 269 as follows:
builder.AppendLine(string.Format("Content-Disposition: attachment; filename="{0}"", ((Attachment)view).Name));
Step to reproduce:
Code example:
public static void Serialize(MailMessage message, string file)
{
using (var stream = new FileStream(file, FileMode.Create))
{
new BinaryFormatter().Serialize(stream, (SerializableMailMessage)message);
}
}
public static MailMessage Deserialize(string file)
{
using (var stream = File.OpenRead(file))
{
return (SerializableMailMessage)new BinaryFormatter().Deserialize(stream);
}
}
static void Main(string[] args)
{
using (var mail = new MailMessage())
{
mail.Attachments.Add(new Attachment(@"c:\temp\attachment.pdf"));
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "subject";
mail.Body = "body";
Serialize(mail, @"c:\temp\mail.bin");
}
MailMessage tmp = Deserialize(@"c:\temp\mail.bin");
Serialize(tmp, @"c:\temp\tmp.bin");
Deserialize(@"c:\temp\tmp.bin"); // <-- System.FormatException
}
Exception details:
System.FormatException was unhandled
HResult=-2146233033
IsTransient=false
Message=The date is in an invalid format.
Source=System
StackTrace:
at System.Net.Mime.SmtpDateTime.ParseValue(String data, String& timeZone)
at System.Net.Mime.SmtpDateTime..ctor(String value)
at System.Net.Mime.ContentDisposition.<.cctor>b__0(Object value)
at System.Net.TrackingValidationObjectDictionary.PersistValue(String key, String value, Boolean addValue)
at System.Net.TrackingValidationObjectDictionary.Add(String key, String value)
at S22.Mail.SerializableAttachment.op_Implicit(SerializableAttachment attachment)
at S22.Mail.SerializableMailMessage.op_Implicit(SerializableMailMessage message)
at ConsoleApplication3.Program.Deserialize(String file) in c:\..\Program.cs:line 34
at ConsoleApplication3.Program.Main(String[] args) in c:\..\Program.cs:line 53
InnerException:
Hello. When I receive mails using S22, for characters with accent (like á, é, í, ó, ú) I have problems.
For example, instead of "la solución es" I receive "la soluci???n es".
How can I fix that?
Regards!
When setting properties (CreationDate, FileName, ModificationDate, ReadDate) of ContentDisposition
is automatically performed the addition of the respective element to the list of parameters.
Subsequently, while copying the parameters you need to check if they are not already present.
Currently this missing check generates an exception during deserialization.
Code example :
public static void Serialize(MailMessage message, string file)
{
using (var stream = new FileStream(file, FileMode.Create))
{
new BinaryFormatter().Serialize(stream, (SerializableMailMessage)message);
}
}
public static MailMessage Deserialize(string file)
{
using (var stream = File.OpenRead(file))
{
return (SerializableMailMessage)new BinaryFormatter().Deserialize(stream);
}
}
static void Main(string[] args)
{
var mail = new MailMessage();
var attachment = new Attachment(@"c:\foo.pdf");
attachment.ContentDisposition.CreationDate = DateTime.Now; // <-- set property
mail.Attachments.Add(attachment);
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "subject";
mail.Body = "body";
Serialize(mail, @"c:\mail.bin");
var tmp = Deserialize(@"c:\mail.bin"); // <-- System.ArgumentException
}
Exception details :
System.ArgumentException was unhandled
Message=An item with the same key has already been added.
Source=mscorlib
StackTrace:
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at System.Net.TrackingValidationObjectDictionary.PersistValue(String key, String value, Boolean addValue)
at System.Net.TrackingValidationObjectDictionary.Add(String key, String value)
at S22.Mail.SerializableAttachment.op_Implicit(SerializableAttachment attachment)
at S22.Mail.SerializableMailMessage.op_Implicit(SerializableMailMessage message)
at ConsoleApplication1.Program.Deserialize(String file)
at ConsoleApplication1.Program.Main(String[] args)
[...]
InnerException:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.