want to launch outlook with attachemnet for new mail with c# code

  • Thread starter hemaneelagiri via OfficeKB.com
  • Start date
H

hemaneelagiri via OfficeKB.com

hi
i want to lanuch outlook(default mail client) with an attachment
i am able to lanuch outlook with all except attachment
like bellow
string strAttach = "C:\\test.txt";
string mailto = string.Format("mailto:{0}?Subject={1}&Body={2}
&Attach={3}", "", "Test Mail", "Hema", strAttach);
//System.Diagnostics.Process.Start(mailto);

Process myProcess = new Process();
myProcess.StartInfo.FileName = mailto.ToString();
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.RedirectStandardOutput = false;
myProcess.Start();
myProcess.Dispose();

but attachment is not coming

pelase help me
 
K

Ken Slovak - [MVP - Outlook]

Some combinations of startup switches don't work together. You can test that
in the UI by starting Outlook using those switches.

In any case you are better off starting an Outlook session and using the
CreateItem() method to create the email and then you can use the object
model to set subject, attachments, recipients, etc.
 
H

hemaneelagiri via OfficeKB.com

Thanks for your response

you mean to say Crete item. i am able to create item.. but how can we launch
that created mail

please see below code

Outlook._Application oApp = new Outlook.Application();

Outlook.NameSpace oNS = oApp.GetNamespace("mapi");

oNS.Logon(Missing.Value, Missing.Value, false, true);

Outlook._MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.
olMailItem);

oMsg.Subject = strSubject;

oMsg.Body = strMessage;

fi = new System.IO.FileInfo(arrAttachPaths);
iPosition = (int)oMsg.Body.Length + 1;
oMsg.Attachments.Add(fi.FullName, iAttachType, iPosition, fi.Name);

oMsg.To = strToIds; // use rshoukldenetr the To Id

// send mail.. but here new mail should launch and user will enetr that to
email id

oMsg.Send();

oNS.Logoff();

oMsg = null;
oNS = null;
oApp = null;

please help me


Some combinations of startup switches don't work together. You can test that
in the UI by starting Outlook using those switches.

In any case you are better off starting an Outlook session and using the
CreateItem() method to create the email and then you can use the object
model to set subject, attachments, recipients, etc.
hi
i want to lanuch outlook(default mail client) with an attachment
[quoted text clipped - 15 lines]
pelase help me
 
H

hemaneelagiri via OfficeKB.com

Thanks i got the solution

oMsg.Display(false);


Thanks for your response

you mean to say Crete item. i am able to create item.. but how can we launch
that created mail

please see below code

Outlook._Application oApp = new Outlook.Application();

Outlook.NameSpace oNS = oApp.GetNamespace("mapi");

oNS.Logon(Missing.Value, Missing.Value, false, true);

Outlook._MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.
olMailItem);

oMsg.Subject = strSubject;

oMsg.Body = strMessage;

fi = new System.IO.FileInfo(arrAttachPaths);
iPosition = (int)oMsg.Body.Length + 1;
oMsg.Attachments.Add(fi.FullName, iAttachType, iPosition, fi.Name);

oMsg.To = strToIds; // use rshoukldenetr the To Id

// send mail.. but here new mail should launch and user will enetr that to
email id

oMsg.Send();

oNS.Logoff();

oMsg = null;
oNS = null;
oApp = null;

please help me
Some combinations of startup switches don't work together. You can test that
in the UI by starting Outlook using those switches.
[quoted text clipped - 8 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top