Sending E-mail through default settings
-
Morning CPians, dig me out here :) I need to send an E-mail from my app through the default E-mail setup on a client system. (invoices and order confirmations, exciting stuff) I have learned through some Googles that MAPI used to do this (no I haven't tried, it looks pretty old), then MAPI was replaced by System.Web.Mail, which has now been replaced by System.Net.Mail. Great, BUT, these .NET replacements both need to be told the E-mail server's address and/or domain, which my users will definitely not know. The Outlook automation assemblies look like an easy option, but I'd just as soon not limit myself to Outlook, or move outside .NET Is there some way to have System.Net.Mail just send the mail through whatever default E-mail settings exist on a user's machine? Perhaps I can look up the E-mail settings somewhere? Magically impersonate the user? Ideas? Guidance?
-
Morning CPians, dig me out here :) I need to send an E-mail from my app through the default E-mail setup on a client system. (invoices and order confirmations, exciting stuff) I have learned through some Googles that MAPI used to do this (no I haven't tried, it looks pretty old), then MAPI was replaced by System.Web.Mail, which has now been replaced by System.Net.Mail. Great, BUT, these .NET replacements both need to be told the E-mail server's address and/or domain, which my users will definitely not know. The Outlook automation assemblies look like an easy option, but I'd just as soon not limit myself to Outlook, or move outside .NET Is there some way to have System.Net.Mail just send the mail through whatever default E-mail settings exist on a user's machine? Perhaps I can look up the E-mail settings somewhere? Magically impersonate the user? Ideas? Guidance?
Hi, I use MailMessage, MailAddress, and SmtpClient classes, and keep some strings as settings, including the mail server name (which SmtpClient constructor needs). I know of no way to solve it without settings for all possible situations. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
-
Morning CPians, dig me out here :) I need to send an E-mail from my app through the default E-mail setup on a client system. (invoices and order confirmations, exciting stuff) I have learned through some Googles that MAPI used to do this (no I haven't tried, it looks pretty old), then MAPI was replaced by System.Web.Mail, which has now been replaced by System.Net.Mail. Great, BUT, these .NET replacements both need to be told the E-mail server's address and/or domain, which my users will definitely not know. The Outlook automation assemblies look like an easy option, but I'd just as soon not limit myself to Outlook, or move outside .NET Is there some way to have System.Net.Mail just send the mail through whatever default E-mail settings exist on a user's machine? Perhaps I can look up the E-mail settings somewhere? Magically impersonate the user? Ideas? Guidance?
If you need it to actually display the message in the users default email client (like Outlook, Live Mail, etc.) you can use some interop to MAPI, but you need to be very careful about resource leaks. Keep in mind that this isn't officially supported and is actually not recommended, but I think as long as you are careful and only use it to open a mail message it's safe. Otherwise, you can use the built-in .NET classes but you will need to ask the user for the email server. You can save that information as a setting somewhere so you only need to ask for it once, but there isn't a way (as far as I know) to automatically get that information.
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
-
If you need it to actually display the message in the users default email client (like Outlook, Live Mail, etc.) you can use some interop to MAPI, but you need to be very careful about resource leaks. Keep in mind that this isn't officially supported and is actually not recommended, but I think as long as you are careful and only use it to open a mail message it's safe. Otherwise, you can use the built-in .NET classes but you will need to ask the user for the email server. You can save that information as a setting somewhere so you only need to ask for it once, but there isn't a way (as far as I know) to automatically get that information.
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
Hrmph. Thanks very much both of you, I suspected as much. Cheers! -Jack