Author |
|
juris Groupie
Joined: 27 June 2011 Location: Italy
Online Status: Offline Posts: 72
|
Posted: 26 May 2016 at 4:32am | IP Logged
|
|
|
Hello Igor,
I want to delete only the first "Boundary" and the first "Content-Type"...
Lello
|
Back to Top |
|
|
Igor AfterLogic Support
Joined: 24 June 2008 Location: United States
Online Status: Offline Posts: 6104
|
Posted: 26 May 2016 at 4:46am | IP Logged
|
|
|
You could do that upon generating the message, using GetMessageRawData method. Note that it's highly advanced and unsupported method.
--
Regards,
Igor, AfterLogic Support
|
Back to Top |
|
|
juris Groupie
Joined: 27 June 2011 Location: Italy
Online Status: Offline Posts: 72
|
Posted: 26 May 2016 at 4:53am | IP Logged
|
|
|
This is my code:
==[ Remove boundary and content-type ]====================
byte[] bytes = msg.GetMessageRawData();
string msgString = Encoding.Default.GetString(bytes);
string boundary = "--" + msg.MimePartTree.Boundary;
int start = msgString.IndexOf(boundary);
int lenght = msgString.IndexOf(boundary, start + 1) - start;
string partToRemove = msgString.Substring(start, lenght);
msgString = msgString.Replace(partToRemove, "");
bytes = Encoding.Default.GetBytes(msgString);
msg.LoadMessage(bytes);
=============================================================
Lello
|
Back to Top |
|
|
juris Groupie
Joined: 27 June 2011 Location: Italy
Online Status: Offline Posts: 72
|
Posted: 26 May 2016 at 12:05pm | IP Logged
|
|
|
This code works, but I would have preferred a built-in function :-(
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 27 May 2016 at 1:41am | IP Logged
|
|
|
We don't want to have built-in functionality for this as it would cause too much trouble for many email clients. For instance, some mail clients let you search emails in IMAP mailbox by "has attachments" flag. Internally, they search for "multipart" content-type (because there is no explicit "has attachments" field in message headers). However, email consisting only attachment and no multipart content-type won't be detected this way.
Regards,
Alex
|
Back to Top |
|
|
juris Groupie
Joined: 27 June 2011 Location: Italy
Online Status: Offline Posts: 72
|
Posted: 27 May 2016 at 2:18am | IP Logged
|
|
|
Hello Alex,
I do not use the MIME to send a message.
I use the MIME like a file container!
My "MIME" has no Body!
My "MIME" contains only attachments!
If I use these properties:
============================
msg.Charset = null;
msg.MailTransferEncodingPlain = MailTransferEncoding.None;
msg.MailTransferEncodingHtml = MailTransferEncoding.None;
This means that I do not want a body.
So the first section "" Boundary "and" Content-Type: text / plain "is not necessary.
=======================
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 27 May 2016 at 3:15am | IP Logged
|
|
|
Again, that's not possible out-of-box.
Regards,
Alex
|
Back to Top |
|
|
juris Groupie
Joined: 27 June 2011 Location: Italy
Online Status: Offline Posts: 72
|
Posted: 27 May 2016 at 3:13pm | IP Logged
|
|
|
Hello Alex,
If I can not delete this section there is a way to turn this section into an attachment?
Lello
|
Back to Top |
|
|
juris Groupie
Joined: 27 June 2011 Location: Italy
Online Status: Offline Posts: 72
|
Posted: 28 May 2016 at 1:14am | IP Logged
|
|
|
Hello Alex,
I solved the problem by transforming the body in the attachment:
Regards, Lello
====================================
msg.Headers.Add("Content-ID", "<DatiAtto.xml>", false);
msg.Headers.Add("Content-Disposition", "inline; filename='DatiAtto.xml.p7m'", false);
msg.LoadBodyText("DatiAtto.xml.p7m", MessageBodyType.Plain, Encoding.Default, ImportBodyOptions.Append);
msg.MailTransferEncodingPlain = MailTransferEncoding.Base64;
=====================================
|
Back to Top |
|
|
juris Groupie
Joined: 27 June 2011 Location: Italy
Online Status: Offline Posts: 72
|
Posted: 28 May 2016 at 10:32pm | IP Logged
|
|
|
Hello Alex,
1) - Your "LoadBodyText" function does not allow the user to specify "targetFilenme" and does not automatically add "Content-Disposition: filename = xxxxxxxx.
2) - Your "LoadBodyText" function does not allow the user to specify the "Content-ID: yyyyyyy".
You can add these two features?
Regards, Lello
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 30 May 2016 at 2:36am | IP Logged
|
|
|
You can make body appear as attachment like below:
Code:
MailMessage mu = new MailMessage();
mu.Charset = "windows-1252";
mu.BodyParts.Clear();
TextBodyPart tp = mu.BodyParts.Add("text/plain"); // or application/pkcs7-mime or whatever content-type you need
tp.TransferEncoding = MailTransferEncoding.Base64;
tp.Headers["Content-Disposition"] = "attachment; filename=\"DatiAtto.xml.p7m\"";
tp.Text = "string containing your attachment data";
mu.SaveMessage(@"C:\Temp\1.eml");
|
|
|
The result will be:
Code:
MIME-Version: 1.0
X-Mailer: MailBee.NET 10.0.2.540
Content-Type: text/plain;
charset="windows-1252"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="DatiAtto.xml.p7m"
c3RyaW5nIGNvbnRhaW5pbmcgeW91ciBhdHRhY2htZW50IGRhdGE=
|
|
|
|
Back to Top |
|
|
juris Groupie
Joined: 27 June 2011 Location: Italy
Online Status: Offline Posts: 72
|
Posted: 30 May 2016 at 3:58am | IP Logged
|
|
|
Hello Alex,
It works perfectly.
Thank you :-)
Lello
|
Back to Top |
|
|