System.Diagnostics.Process.Start c# query

J

JimJob

Hi All,

I am using c# to build an application. I want a button that will be able to
open a new mail message with an attachment. The new mail message works but I
can't get the attachment to work - there is no error message just no
attachment. Any ideas? Code i am using is;

System.Diagnostics.Process.Start("mailto:[email protected]?subject=Software&body=see attachment&attachment=c:/myview.mht");

Thanks
 
D

DeveloperX

Hi All,

I am using c# to build an application. I want a button that will be able to
open a new mail message with an attachment.  The new mail message works but I
can't get the attachment to work - there is no error message just no
attachment.  Any ideas?  Code i am using is;

System.Diagnostics.Process.Start("mailto:[email protected]?subject=Software&body=see attachment&attachment=c:/myview.mht");

Thanks

try c:\ and prefix the string with an @

ie

(@"mailto:[email protected]?subject=Software&body=see
attachment&attachment=c:\myview.mht"

@ will stop the compiler treating \ as an escape character.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

I'm not sure if you can do it. mailto is intended to be used from a webpage,
there is no way to attach a local file from a webpage's link
 
D

DeveloperX

Thanks developer - but no joy.  I have also tried @ C:\ or C:/ to no avail






- Show quoted text -

Ignacio appears to be correct, my apologies. You could always add a
reference to System.Web.Mail and use the classes in there. having a
quick poke, I got:

using System.Web.Mail;


MailMessage message = new MailMessage();
message.From = "(e-mail address removed)";
message.Body = "body";
message.To ="(e-mail address removed)";
message.Subject = "subject";
message.Attachments.Add(new MailAttachment(@"C:\boot.ini"));
SmtpMail.SmtpServer = "smtp.mailserver.com";
SmtpMail.Send(message);

should do it, but if you get a "CDO.message not found" message that's
to do with authentication. (I got that error, there seem to be alot of
posts about it!)


alternatively I managed to get this to work using outlook interop, but
again, outlook now has all that cruddy security so it pops up a dialog
saying is this ok?? I'm sure I've read about ways of disabling that,
but it was a while ago.

using Microsoft.Office.Interop.Outlook;


Microsoft.Office.Interop.Outlook.Application app =
new Microsoft.Office.Interop.Outlook.ApplicationClass();
MailItem message = (MailItem)app.CreateItem(OlItemType.olMailItem);

Recipient recip =
(Recipient)message.Recipients.Add("(e-mail address removed)");
recip.Resolve();

message.Body = "body";
message.Subject = "subject";
message.Attachments.Add(@"C:\boot.ini",
OlAttachmentType.olByValue,message.Body.Length + 1, "an attachment");
//message.Save();
//message.Display(false);
message.Send();


probably no help, but you never know.
 
J

JimJob

Thanks Developer - I am attempting to to try your second solution - however
it dosent like "using Microsoft.Office.Interop.Outlook;" am i missing a
required reference? Asking permission to use outlook wont cause a problem
for me.

I tried the System.Web.Mail method and that works fine - but I would prefer
that on the click of a button a new mail message window opens with the
attachement and the user then inputs what they want and then click on send.
Rather then a message being sent in the back ground with no user interaction
which is the case of the System.Web.Mail .

I feel i am getting close to the solution.....thought it would be easier
though!

Thanks
 

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