abhimanu

Hi ,

I am trying to develop a project that receives new mail in the form of a continuos string separated my delimiters and also contains attachment as byte array.

How could I convert these string into my mail item and save it into my custom folder during runtime.

Thanks in advance.

Regards

Div



Re: Visual Studio Tools for Office How to convert string to new mail

Ji Zhou – MSFT

Hi Div,

Of course, you can create a new Mail Item in your inbox, and then set its properties, such as subject, body and so on, to values you retrieved from your string. But how to retrieve information from your string is off-topic in this forum. I think you can use string.Split() method to do such a thing. You can get more information from C# language forum. And the following codes are about how to create an email and set its properties.

Code Snippet

private void ThisAddIn_Startup(object sender, System.EventArgs e)

{

Outlook.Folder folder = this.Application.Session.GetDefaultFolder

(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox) as Outlook.Folder;

Outlook.MailItem mail = folder.Items.Add(Outlook.OlItemType.olMailItem) as Outlook.MailItem;

mail.Subject = "Hello";

mail.Body = "This is a test email";

mail.To = "someone@microsoft.com";

mail.Save();

mail.Move((Outlook.MAPIFolder)folder);

}

Thanks

Ji






Re: Visual Studio Tools for Office How to convert string to new mail

Dparora

Hi Ji,

I tried to did this .. but I am facing once problem .

When I create a mail it just creates a new mail and saves into my custom folder with the line "Mail has not been sent"..

My task is to break the string into respective fields and then move it to my Custom folder as the received mail.

Moreover how can I stored sender;s name into it.

Thanks in advance.





Re: Visual Studio Tools for Office How to convert string to new mail

Sue Mosher - Outlook MVP

Do you mean that you want to create a message that looks just like a sent message That's not possible with Outlook objects. I'd recommend that you take a look at Outlook Redemption -- http://www.dimastr.com/redemption/ -- or prepare yourself to dig into Extended MAPI (which is not directly supported in .NET).





Re: Visual Studio Tools for Office How to convert string to new mail

Dparora

Hi Sue,

I just want the message as a New Received method.

Say for example I am getting the following string <To: Div, From : Sue, Body : Outllook Addin"....>

I need to spilt the string into individual items and then put it into my Custom folder as New Message.

I tried to create a message by creating the mailitem object and then storing object. to == "Div" , object.Body="Outlook Addin", but coudnt find the way to store From field as this only creates a New Mail to send and not as Received.

Thanks

Div





Re: Visual Studio Tools for Office How to convert string to new mail

Sue Mosher - Outlook MVP

Exactly my point. If you want a mesage to look like you sent it, you can create the item as a PostItem, then change the MessageClass to "IPM.Note," but I know of no way to make it look like someone else sent it other than to use Redemption to import or to use Extended MAPI (which is what Redemption uses).





Re: Visual Studio Tools for Office How to convert string to new mail

Dparora

Hi Sue,

Thanks a lot for a valuable session.

Will try to work on redemption.

Thanks a lot once again.

Regards

Div





Re: Visual Studio Tools for Office How to convert string to new mail

Dparora

Hi Sue,

I am able to save the message using the messge class conversion to ipm.note. I was able to manipulate the sender's name using redemption but the problem if I send the message in the inbox it shows the sender name as mine name and not the changed sender name. But in the Sent Item it shows different sender name but when i click on reply it takes my account address.

The code segment that I was using is as follows :

RDOFolder folder = session.GetDefaultFolder(rdoDefaultFolders.olFolderInbox);

RDOMail rdomail = folder.Items.Add(rdoItemType.olMailItem);

rdomail.To = "d@ms.com";

rdomail.Subject = "Outlook";

rdomail.SentOnBehalfOfEmailAddress = dummy@yahoo.com;

rdomail.SenderName = "Sender";

rdomail.Body = "This is outlook testing";

rdomail.SenderEmailAddress = dummy@yahoo.com;

rdomail.Save();

SafeMailItem mailitem = new SafeMailItemClass();

mailitem.Item = rdomail;

int tag = 0x0C1A001E;

mailitem.set_Fields(tag, dummy@yahoo.com);

mailitem.Send();

Kindly help me on this..





Re: Visual Studio Tools for Office How to convert string to new mail

Sue Mosher - Outlook MVP

Sorry, but I don't understand what this has to do with your original question. It looks like you're just creating and sending a conventional message, not saving a message in a folder and trying to set all its properties so that it looks like a sent message. Unless you're working in an Exchange environment, setting SentOnBehalfOfEmailAddress isn't necessarily going to work the way you expect. If you want replies to go to a different address, use the ReplyRecipients collection.

I don't have the MAPI property tags memorized, so maybe you can tell us what 0x0C1A001E is supposed to do.





Re: Visual Studio Tools for Office How to convert string to new mail

Dparora

Hi Sue,

Thanks a lot for your reply.

Actually when I am using Safeitem object there is no Save method in it , it Actually has SaveAS method that stores the file in the path that I specify and if I retreieve it it doesn't shows me from field as Null.

When I send the message i observe two things.

1. I get a message in my inbox from System Administrator that your mail cannot be send.

2. The mail that I created is stored in the deleted folder. which contains all the customize field.

I will update the code .

thanks

div