Saving a created .msg file as readonly - c#

Hi I had a requirement wherein I convert dxl to .msg file. Since there is no out of the box .NET way to do so, I parsed the xml, got the required fields out, created a .msg file using Microsoft.Office.Interop.Outlook. But when I open the file it looks like a draft mail, ready to be sent. But I would want the file to open as an inbox mail or a sent mail, wherein the fields are 'Not Editable' meaning should be readonly.
My code:
mailitem.To = "reciever#recieve.com";
mailitem.SentOnBehalfOfName = "sender#send.com";
mailitem.Subject = "Test for MSG";
mailitem.Body = "Sample Body";
mailitem.SaveAs(temppath + ".msg", OlSaveAsType.olMSG);
There is something called SaveSentMessageFolder in mailItem, couldn't figure out how to do so.
Thanks

Related

determine if a message was sent or closed outlook

in c # I create a message m before sending it I show the user who can edit it and send or close it. How can I track the user closed this message or sent.
OutLookRef.Application oApp;
oApp = new OutLookRef.Application();
OutLookRef.MailItem mail = oApp.CreateItem(OutLookRef.OlItemType.olMailItem);
var pInspector = mail.GetInspector;
mail.Recipients.Add(address);
mail.Subject = subject;
mail.HTMLBody = body;
mail.Display();
All I got was to pause the code while this window is open
while (pInspector.CurrentItem is OutLookRef.MailItem)
{
System.Threading.Thread.Sleep(500);
}
also after sending, I would like to save this message to a disk, let's say mail.msg
It seems you are interested in the following properties:
MailItem.SendUsingAccount returns an Account object that represents the account under which the MailItem is to be sent.
MailItem.SentOnBehalfOfName returns a string indicating the display name for the intended sender of the mail message.
Namespace.CurrentUser returns the display name of the currently logged-on user as a Recipient object.
also after sending, I would like to save this message to a disk, let's say mail.msg
You may hook up to the ItemAdd event of the Items class which belongs to the Sent Items folder where you can save the item on the disk. The MailItem.SaveAs method saves the Microsoft Outlook item to the specified path and in the format of the specified file type. If the file type is not specified, the MSG format (.msg) is used.

Convert from .eml to .msg in C# .NET

I want my users to fill out a simple form with fields like From, To, Subject, Body and Attachments. When they are done they should click on a button which lets them download a .msg file, so that they can edit it furthermore in outlook and send it.
All the converters APIs I've found for .NET are commercial (and quite pricy).
Here's my code:
using System.Net.Mail;
protected void lbOpenOutlook_Click(object sender, EventArgs e)
{
CreateEmail();
}
internal void CreateEmail()
{
// Create message
MailMessage message = new MailMessage();
// subject
message.Subject = "email subject";
// body content
message.Body = "email message.";
// sender
message.From = new MailAddress("sender#gmail.com");
// send this mail to
message.To.Add("test1#gmail.com");
// cc list
message.CC.Add("ccuser1#gmail.com");
// Create the SMTP Client object
SmtpClient smtpClient = new SmtpClient();
// store in directory
smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
// path of the pickup folder
smtpClient.PickupDirectoryLocation = Server.MapPath("~/Emails/");
// deliver email
smtpClient.Send(message);
}
This generates a .eml file..how could I convert it to a .msg whitout using a commercial API?
Also, I don't want to use Microsoft.Office.Interop.Outlook namespace because it works fine on the client but it's not supported on the server and my application is running under IIS.
Note: Summary of comments on the answer.
Whilst Outlook 2007 does not support opening .eml files, Outlook 2010+ can open .eml files correctly.
To convert EML to MSG you can use Aspose.Email for .Net.
This is a third-party library, which can provide you with a bunch of useful functions for working with email.
The Email API can be used for basic email management features such as converting, message content attachment manipulation and editing, and for its advanced features such as management of the message storage files, sending & receiving emails via several protocols including POP3, IMAP & SMTP.
You can do it programmatically. For example, you can use the following code:
//Initialize .EML file
using (MailMessage eml = new MailMessage("test#from.to", "test#to.to", "template subject", "Template body"))
{
string oftEmlFileName = "EmlAsMSG_out.msg";
MsgSaveOptions options = SaveOptions.DefaultMsg;
//Save created .MSG file
options.SaveAsTemplate = true;
eml.Save(oftEmlFileName, options);
}
I think this approach can be useful for you.
I am a Developer Evangelist at Aspose.

C# Pdf Attachment damaged when sent to yahoo mail addresses

I'm trying to send an Email with an attached PDF file. When I send it to any other mail provider it works just fine, but when I send it to a yahoo email address, the receiver gets a damaged pdf file. The exact message it gives is:
Adobe Reader could not open 'Filename.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
Because the other email providers were working, I used the following code specifically for yahoo addresses.
if (thisItem.EmailAddress.ToUpper().Contains("YAHOO")){
ContentType contentType = new ContentType();
contentType.CharSet = Encoding.UTF8.WebName;
Attachment theFile = new Attachment(attachmentPath, contentType);
theFile.Name = theFile.Name.Replace("_","");
mm.Attachments.Add(theFile);
}
I've tried a variety of CharSets on the ContentType, hoping that would fix something, no change. I also tried different TransferEncodings on theFile, also no fix. I read somewhere that the file name could cause problems if it had special characters so I removed all the underscores in the name, all that's left is some letters and numbers. I'm not sure what else to try at this point. Any suggestions?

Is it possible to set the position of an Attachment in a MailItem?

I'm trying to position an attachment in an RTF mail of Outlook 2007 created via COM:
using Outlook = Microsoft.Office.Interop.Outlook;
// ...
private static void CreateMailWithAttachment()
{
Outlook.Application ol = new Outlook.Application();
Outlook.MailItem mail = (Outlook.MailItem) ol.CreateItem(Outlook.OlItemType.olMailItem);
mail.BodyFormat = Outlook.OlBodyFormat.olFormatRichText;
mail.Subject = "Important e-mail";
mail.Body = "1234567890 1234567890 1234567890";
mail.Attachments.Add(#"c:\myfile.txt", Outlook.OlAttachmentType.olByValue, 2);
mail.Display();
}
The documentation of Attachments.Add does not explicitly say what happens when a value between 2 and the length of the mail is used:
This parameter applies only to e-mail messages using Microsoft Outlook Rich Text format: it is the position where the attachment should be placed within the body text of the message. A value of 1 for the Position parameter specifies that the attachment should be positioned at the beginning of the message body. A value 'n' greater than the number of characters in the body of the e-mail item specifies that the attachment should be placed at the end. A value of 0 makes the attachment hidden.
I'm seeing the following behavior:
0: Works as described, attachment is hidden.
1: Does not work as described, attachment is at the end of the body.
> 1: Attachment is at the end of the body.
It's the same when starting Outlook with command line arguments /noextensions or /safe.
Is it possible to position an attachment in the middle of a mail? Am I missing something?
I guess it's KB967677, although I'm pretty sure the patch is installed. It works perfectly with Outlook 2003.
Sorry for bothering.

Managing Lotus Notes Mail Format using C#

I am accessing mail body and fetching it in another mail.
But i am not getting original format of previous mail in new mail.
Problem i am facing in this situation are:
Not getting images in destination mail.
Font is also varying.
I am accessing mail body as follows:
NotesRichTextItem rtItem = (NotesRichTextItem)docInbox.GetFirstItem("Body");
String Body = rtItem.GetFormattedText(false , 0);
String bodyFormat = rtItem.type.ToString();
also tried this code:
NotesItem itemBody = docInbox.GetFirstItem("Body");
String bodyFormat = itemBody.type.ToString();
String Body = itemBody.Text;
But not getting solution in both case.
If you're trying to access rich text from Lotus Notes and put it into your own system, that will be very difficult and the NotesAPI is of little help to you. However, if you are trying to copy a rich text item from one NotesDocument to another, look at the AppendRTItem method of the NotesRichTextItem class.

Categories

Resources