| Author |  | 
      
        | paaltuv Newbie
 
  
 
 Joined: 30 October 2012
 Online Status: Offline
 Posts: 2
 | 
          I'm trying to send an email which is encoded with Quoted-Printable, but I'd like a small part of that email to be excempt from the encoding.
           | Posted: 30 October 2012 at 8:50am | IP Logged |   |  
           | 
 |  
 In short I want to be able to insert something like this in the plain body text:
 [[RANDOM]]=
 instead of this:
 [[RANDOM]]=3D
 
 Does anyone have any insight on how I could do this?
 
 Thanks,
 Pål
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Alex AfterLogic Support
 
  
  
 Joined: 19 November 2003
 Online Status: Offline
 Posts: 2207
 | 
          You can generate the e-mail normally, then save MIME output into a memory array or stream (with MailMessage.GetMessageRawData method), then find what you need in the message data and cut 3D off.
           | Posted: 30 October 2012 at 9:30am | IP Logged |   |  
           | 
 |  
 I.e. you will need to perform search over byte array or stream. .net does not provide functions for this but it's not difficult to implement such function. Or, you can simply convert the byte output into a string using Encoding.GetEncoding(1252).GetString(bytes), then search that string and remember the indices found. These indices in the string will be the same as in the byte array because 1252 encoding always produces the same number of characters like in the source byte array.
 
 Thus, when you found that "[[RANDOM]]=" is at, let's say 567 offset, you will need to combine your resulting array from 0,567 block and from 567+len("[[RANDOM]]"),-1 block (assuming -1 means the rest of the byte array). Of course, if you have multiple entries which need to be cut, the procedure must be repeated in a loop.
 
 Once you have the corrected MIME source, you can load it into MailMessage with .LoadMessage(byte array or stream), and you can send it. The MailMessage object in question can be the one in Smtp.Message property:
 
 
| Code: 
 
    
    | 
      
       | smtp.Message.BodyPlainText = "smth";
 ...
 bytes1 = smtp.Message.GetMessageRawData();
 string1 = Encoding.GetEncoding(1252).GetString(bytes1);
 // then, find N = how many times "[[RANDOM]]=" appears in the string1
 // then, create bytes2 array which is less than bytes1 by N * len("3D")
 // then, fill bytes2 by blocks of bytes1 between "[[RANDOM]]=3D" entries so
 // that "3D" would be cut off.
 ...
 smtp.Message.LoadMessage(bytes2);
 smtp.Send();
 
 |  |  |  | 
       
        | Back to Top |     | 
       
       
        |  | 
        | paaltuv Newbie
 
  
 
 Joined: 30 October 2012
 Online Status: Offline
 Posts: 2
 | 
          Great answer, thanks!
           | Posted: 30 October 2012 at 11:47am | IP Logged |   |  
           | 
 |  | 
       
        | Back to Top |     | 
       
       
        |  |