WolfmanYoda Posted March 24, 2004 Posted March 24, 2004 Hello all, I'm still a little new with C# and ran into a brick wall. I have a textbox on my form which contains an email address. I also have a button that when pressed, would have Outlook open up, bring up a New Message window, and have the To: field already filled out with the address from my textbox. MSDN got me this far, which will just open up Outlook: Process myProcess = new Process(); myProcess.StartInfo.FileName = @"Outlook.exe"; myProcess.StartInfo.Arguments = ""; myProcess.Start(); Which is great, but isn't there some arguments I can put into that 3rd line which will get Outlook to start a new message with the To: field filled out? Thank you, sorry if this has been asked before, but Search didn't help. Quote
Roey Posted March 24, 2004 Posted March 24, 2004 This is what I use in VB, should be the same Private Sub butEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butEmail.Click System.Diagnostics.Process.Start("mailto:" & txtContactEmail.Text) End Sub Quote
WolfmanYoda Posted March 24, 2004 Author Posted March 24, 2004 Thanks, I'm on my way out the door now, but I will try this when I get back. Quote
WolfmanYoda Posted March 24, 2004 Author Posted March 24, 2004 Ok, I think that may work once I get an error fixed. It tells me that txtMailTo.text is inaccessable due to its protection level. I've tried changing private System.Windows.Forms.TextBox txtMailTo; to this: public System.Windows.Forms.TextBox txtMailTo; in my Form class but that didn't work. This is probably pathetically easy to fix, but I'm at a loss. Quote
Roey Posted March 25, 2004 Posted March 25, 2004 There's something wrong in your code somewhere causing that error. Can you post the code relative to that textbox and I'll have a look. This error can occur in C# due to the fact that Text is a case sensitive word. Quote
WolfmanYoda Posted March 25, 2004 Author Posted March 25, 2004 Ok, after some more fooling around I have this code: public void btnSendEmail_Click(object sender, System.EventArgs e) { Process myProcess = new Process(); myProcess.StartInfo.FileName = @"Outlook.exe"; myProcess.StartInfo.Arguments = ""; myProcess.Start("mailto:" & editEmail.Text); } And now it gives me and error for using '&': Operator '&' cannot be applied to operands of type 'string' and 'string' I tried changing & to + but that didn't work, either. At least the protection error is gone :-\ Quote
Administrators PlausiblyDamp Posted March 25, 2004 Administrators Posted March 25, 2004 what error di you get using + instead of &? If you step through the code in the debugger what does "mailto:" + editEmail.Text equal? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
WolfmanYoda Posted March 25, 2004 Author Posted March 25, 2004 When I use a + I get two errors: cs(1051): Static member 'System.Diagnostics.Process.Start(string)' cannot be accessed with an instance reference; qualify it with a type name instead cs(1051): The type or namespace name 'myProcess' could not be found (are you missing a using directive or an assembly reference?) Which both refer to the mailto line. The second one is weird because in my code that is the third line to use 'myProcess', but only that line has a problem with 'myProcess' Quote
Administrators PlausiblyDamp Posted March 25, 2004 Administrators Posted March 25, 2004 public void btnSendEmail_Click(object sender, System.EventArgs e) { Process.Start("mailto:" + editEmail.Text); } will do the trick for you. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
WolfmanYoda Posted March 25, 2004 Author Posted March 25, 2004 Thank you, it actually compiled that time :D But it threw an exception when I hit the Send Email button: An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in system.dll Additional information: The specified module could not be found I really appreciate all of the help you guys have given me, but I think at this point I'm just wasting your time. The answer must be buried in the MSDN somewhere, I'll give that another shot. I'll let you know if I get it working. Thanks again :cool: Quote
Administrators PlausiblyDamp Posted March 25, 2004 Administrators Posted March 25, 2004 Sounds like a problem with Outlook not being properly registered on your PC. If you go to the start button, then run and just type mailto:somebody@somewhere.com what happens after you hit OK? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
WolfmanYoda Posted March 25, 2004 Author Posted March 25, 2004 Sounds like a problem with Outlook not being properly registered on your PC. If you go to the start button, then run and just type mailto:somebody@somewhere.com what happens after you hit OK? It works just as expected, a new message window opens with the 'To' field containing 'somebody@somewhere.com'. Could it have something to do with my textbox text coming from a database instead of just regular text? Quote
Administrators PlausiblyDamp Posted March 25, 2004 Administrators Posted March 25, 2004 Can't think why it doesn't work then? Does the text box contain just the e-mail address? You may want to strip white space from the textbox to be on the safe side. public void btnSendEmail_Click(object sender, System.EventArgs e) { Process.Start("mailto:" + editEmail.Text.Trim()); } Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
WolfmanYoda Posted March 25, 2004 Author Posted March 25, 2004 Ok, now it's just wierd. Just to see if it could be Outlook, I made a new project with just a textbox containing an email address set at design time and a button for the 'mailto:' statement to see if it would work. It worked perfectly, so I know your code line is right. I went back to my Contact Book project and tried 'Trim' on my textbox but it still gave me the same error. Maybe I should just start the program over and pay more attention to my P's and Q's? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.