How to send emails from an app

Status
Not open for further replies.

RonNYC

Member
Joined
Jan 2, 2013
Messages
8
Programming Experience
10+
I'm not sure this is the right forum for this question, so apologies in advance.

My app is a C#/Winform app (VS 2019). It will let users send emails with app data. The users add recipients in a form and then click send email.
The sendEmail() procedure constructs a string somewhat like this:

"mailto:billy10101010106@gmail.com?subject=Your rent is late again&body=Ratcliffe, who was first elected to the House in 2014"

The next line is:
Process.Start(mailto);

and that doesn't error out but what happens is the Microsoft Mail app is invoked. This is OK in that I don't want my program to mail anything out without the user's explicit action.
So in the Microsoft Mail app, I click Send and...nothing happens, usually. On occasion, it works, but very seldom. Or it takes 10-15 min to send and after I click Send, there is nothing. No message in Sent or Sent Mail (what's the difference?) or anywhere.

I don't care about the Microsoft Mail app, I just want the user to be able explicitly email. I thought this should go to the default mail system, which for me is gmail, but it doesn't.

RON
 
Last edited:
Look at the System.Net.Mail namespace, you'll see there's objects like MailAddress, MailMessage, SmtpClient, & anything else you'd need to put together and send an email.
 
I was hoping sending email programmatically in Windows would be similar to using Android, but it's not, apparently. In my Android app I just send the email and the Android system let's me decide how to send it.

There is nothing similar for Windows?

It seems using Net.Mail, I have to put the user's password during the running of the app. On Android, this is done outside the app, so the app doesn't know what email system the user wants to use.
 
Last edited:
System.Net.Mail could be better, but if you only want something raw and basic, try the above. You could shop around for a better library, although most libraries are built in and around the class above. Libraries tend to offer better integration though, so I'd look there. Take your pick from the available packages on nuget musthaves Best 20 NuGet email Packages or try : MailMerge or jstedfast/MailKit
 
Unless I'm missing something almost all the recommendations above are missing out on the key requirement that the OP is looking for: He wants to send email using the user's current email provider without having to know the current user credentials to be able to send that email.

So that pretty much knocks using System.Net.Mail out of the running since you would have to instantiate an SmtpClient and somehow pass in the name of the SMTP server that the user uses, and the credentials needed to log on to that SMTP server.

That also knocks out all the packages where you would use a 3rd party mailing service because you won't be using the user's current email provider. Even if the 3rd party mailing service could make the "From:" field appear as if it came from the user, the mail headers of the message that is sent would tell the tale that email came from the mailing service -- unless the mailing service allows you to spoof the mail headers.

I know that the OP's program would have fits no my machine. I deliberately did not configure my Win10 Mail App, but had Win10 set to use Mail App as my default email client. I use Outlook 2016 for my heavy duty read/writing of email. I also have 3 different email providers I use depending who I'm trying to contact and/or where I want a particular class to go. Within those providers I have multiple mailboxes to even make things more complicated.
 
You are correct and phrased it much better than I did. I am writing two apps, one on Android and one on Windows (with which I am much more familiar). But I did the email part on the Android first and it was very easy. So, I thought, how much of a pain could Windows be. And it is. I never ever used the Microsoft Mail app. To me it was just more bloatware. And I thought using Process.Start(mailto) would be a no brainer and it almost is. All the emails I sent using Microsoft Mail got delivered (I think) but like 3+ hours later. No idea why this isn't immediate. If it were, I'd be happy. Still, I'm thinking there may not be a good solution to my problem. I don't want to do things the user is not aware of that affects this system, like sending mail. And I don't want to saddle users with some kind of long-winded installation.

Is there no solution?

RON
 
A Windows machine has a default app for handling the "mailto" protocol, much as it does for handling the "http" protocol and others. If you call Process.Start and pass a "mailto" string then Windows will invoke that application. What happens then is nothing to do with your C# application. Process.Start is akin to executing an instruction in a console window. If you do that with the same "mailto" string, what happens?
 
Yes, the C# part is not overly relevant, except if there were some code I could use.
A Windows machine has a default app for handling the "mailto" protocol, much as it does for handling the "http" protocol and others. If you call Process.Start and pass a "mailto" string then Windows will invoke that application. What happens then is nothing to do with your C# application. Process.Start is akin to executing an instruction in a console window. If you do that with the same "mailto" string, what happens?
 
What bothers me about this "new" development (Microsoft Mail), at least on my system, is that the Mail app is opaque.

mailoptions.JPG



I can't change the sync settings (why? who knows?) and the other two choices are just text. Nothing to click on.

The Mail app seems to wait hours and hours before sending mail out.

Well, just now, it seems to be "trying" to send...says "Still working on it"

Why would it take minutes (or hours) to send?

This is the mail version of Your Phone Companion, another buggy and largely useless app.

RON
 
It doesn't seem like your question has anything really to do with C# development and is thus not appropriate for this site. Any quirks of the Microsoft Mail app aren't really relevant. Your call to Process.Start sends a message to Windows and it decides what app to invoke. On my machine, it would be Outlook that handled the new message, not Mail. This thread will be closed. If you have a question that does relate specifically to C# development, please start another thread.
 
Status
Not open for further replies.

Latest posts

Back
Top Bottom