Creating and adding Outlook Signature - c#

I've created a html template with a couple of replacement variables.
Adding the created signature-template as signature for reply and new messages does not seem to get outlook to default to it.
//string signatureName = "Example.htm";
//Set via office-interop new signature as default
//using Microsoft.Office.Interop.Word;
Application app = new Application();
var opt = app.EmailOptions.EmailSignature;
opt.NewMessageSignature = signatureName;
opt.ReplyMessageSignature = signatureName;
app.Quit(); //Also tried WdSaveOptions.wdSaveChanges
Marshal.ReleaseComObject(app);
Outlook displays the added signature (TEST_...) but does not recognize it as default signature. Instead it just removed the previous default signature and now has none.
Is there something else required to tell outlook to set it as default ?

The Outlook object model doesn't provide anything for that. Of course, as a workaround you may use the Word object model for setting signatures as you did in the code above:
Application app = new Application();
var opt = app.EmailOptions.EmailSignature;
opt.NewMessageSignature = "Eugene Astafiev";
opt.ReplyMessageSignature = "E.Astafiev";
app.Quit(); //Also tried WdSaveOptions.wdSaveChanges
Marshal.ReleaseComObject(app);
But you need to assign a real HTML markup or text which represents the signature, not an HTML document filename.
Anyway, all settings are stored in the windows registry. See Set Default Signature outlook for more information.

Apparently the problem was something... quite simple.
string signatureName = "Example.htm";
Outlook/Word expects the signature-name without the file-extension. Passing "Example" instead of "Example.htm" worked.

Related

how to add report rdlc image parameter to get the image from application settings?

In my WinForms application, different users work on the application. Each user, uses it's own logo and name that I store it in app settings. Now, I want to display the app settings image on the reports. I have googled it, as per my search no one talks about this way. Here is what I found and tried it:
this.reportViewer1.LocalReport.EnableExternalImages = true;
string imgFrom = new Uri(Properties.Settings.Default.system_img).AbsolutePath;
ReportParameter parameter = new ReportParameter("img", imgFrom);
this.reportViewer1.LocalReport.SetParameters(parameter);
Before this, I have added a parameter to the report. But this doesn't work in my case.
Any can tell me how to do this?
After editing the code and made two changes in the above code, it works just fine. Here are the changes:
this.reportViewer1.LocalReport.EnableExternalImages = true;
string imgFrom = new Uri(Properties.Settings.Default.system_img).AbsoluteUri; // changed from AbsolutePath to AbsoluteUri
ReportParameter rpImg = new ReportParameter("img", imgFrom);
this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp1, rp2, rpImg }); // add the parameter to another set of parameters that I had before.

Email.Body not updating after editing WordEditor

I have a form region for the reading pane. I retrieve the wordeditor for the forward mail item and then add info to the word document. This seems to work when I don't create and send the email in the same function, but when I want to create a forward email, edit it, and send it, the Email.Body doesn't update.
_email = this.OutlookItem as Outlook.MailItem;
private void SendForwardEmail()
{
Outlook.MailIem fEmail = null;
Word.Document doc = null;
try
{
fEmail = ((Outlook._MailItem)_email).Forward();
doc = GetWordEditor(fEmail);
EditDoc(doc);
var tmp = doc.Range().Text;
var tmp1 = fEmail.Body; // tmp1 won't have what I added to tmp
((Outlook._MailItem)fEmail).Send(); // This will send with the fEmail.Body value
// and won't show edits to the word doc
}
finally
{
Release(doc);
Release(fEmail);
}
}
I use similar code in a form region for composing emails, the difference is that by the time the Send event is triggered, the Email.Body has updated with the edits to the word doc. I've tried fEmail.Save(), but doesn't seem to work. The word editor does save the work because I can access the word editor at a different point and it will still have the edits. The Email.Body just doesn't update with the changes.
EDIT: I'll add that doing the following does update the Email.Body, but seems like a funky solution.
fEmail.Display();
((Outlook.MailItem)fEmail).Close(Outlook.OlInspectorClose.olSave);
Where and when do you run the code? Is it on a secondary thread?
Anyway, I'd suggest starting from releasing all underlying COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook/Word object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. Read more about that in the Systematically Releasing Objects article.

Creating an rtf custom mail item

I'm using redemption to create a custom mail item and save it in the draft folder of my outlook. Currently the mailItem is saved in HTML format. I want to be able to save it in rtf Format. How can I do that ?
Here is the code I am using :
Redemption.RDOSession session = new Redemption.RDOSession();
session.MAPIOBJECT = olApp.Session.MAPIOBJECT;
Redemption.RDOFolder rFolder = session.GetDefaultFolder(Redemption.rdoDefaultFolders.olFolderDrafts);
Redemption.RDOMail rMsg = rFolder.Items.Add("ipm.note.mep");
// modify some custom fields ...
rMsg.BodyFormat = 3;
rMsg.Save();
Outlook.MailItem oMep = olApp.Session.GetItemFromID(rMsg.EntryID);
oMep.BodyFormat = Outlook.OlBodyFormat.olFormatRichText;
oMep.Display(false);
Changing the bodyFormat doesn't seem to work. I also tried the saveAs method with no success. I can change the format manually when the mailItem is open, but I want to do that automatically within my C# code.
Have you tried to set the RDOMail.RtfBody property?

Get Signatures from Outlook and Detecting Body format

I am using COM API to compose an e-mail.
objOutlook = new Microsoft.Office.Interop.Outlook.Application();
mic = (Microsoft.Office.Interop.Outlook.MailItem)(objOutlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem));
mic.To = ccase.Email;
mic.CC = ccase.CC;
mic.Subject = ccase.Subject;
mic.Body = bodyBuffer.ToString();
// below line throws exception ?? Shouldn't it just use what is defined in outlook.
mic.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatUnspecified;
Question:
I want to define body to be plain Text, HTML, or Rich Text based upon what is defined in Outlook by the customer.
How can I retrieve the e-mail signature from Outlook and add it to the end of body ?
Any pointers will be appreciated.
Karephul
We decided not to do this as users might have configured multiple signatures. So, let users add signature in the end.

copyIntoItems() not assigning Title to the document in document library

I am trying to assign a Title to already existing document in the document library using copyIntoItems().
I am giving input as: Title,ID,FileName
The method is giving the following error:
Value does not fall within expected range
But if I provide SourceFullPath,Title,ID,FileName as the input, then it works fine. I don't want to provide <SourceFullPath>D:\test.txt</SourceFullPath> here.
Can someone suggest how I can use copyIntoItems without providing the SourceFullPath?
To assign the field information you must set at least DisplayName, Type and value to Fields parameter from CopyIntoItems method (http://msdn.microsoft.com/en-us/library/copy.fieldinformation_members%28v=office.12%29.aspx):
fieldInfo = new Sharepoint.FieldInformation();
fieldInfo.Id = Microsoft.SharePoint.SPBuiltInFieldId.Title;
fieldInfo.Value = "New title";
fieldInfo.DisplayName = "Title";
fieldInfo.Type = YetAnotherMigrationTool.Library.SP2007.Sharepoint.FieldType.Text;
fieldInfo.InternalName = "Title";
fields.Add(fieldInfo);
For a full example how to upload a document to SharePoint using CopyIntoItems method see here
Note: The absolute source URL of the document to be copied is a mandatory parameter.

Categories

Resources