Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,

I have my own server, and I also used it for sending and receiving mail. After being hacked for the second time I gave up and signed up for gmail handling my email, using my own domain.
I also have two-step verification enabled, being hacked twice makes you cautious.

I want to send emails from my c# windows forms applications, so I've set up the app specific passwords. Still Google complains about secure connection or client not verified (5.5.1 Authentication required).

When doing a search you find a lot of advice to turn of protection for less secure apps, that's not what I want to do.

Thanks for your thoughts.

What I have tried:

var fromAddress = new MailAddress("myemail@mydomain.toplevel", "From Name");
var toAddress = new MailAddress("myemail@mydomain.toplevel", "To Name");
const string fromPassword = "abcdefghijklmnop"; //app specific password
const string subject = "test";
const string body = "This is a test!!";

var smtp = new SmtpClient
{
    Host = "smtp.gmail.com",
    Port = 587,
    EnableSsl = true,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
    Timeout = 20000
};
using (var message = new MailMessage(fromAddress , toAddress)
{
    Subject = subject,
    Body = body
})
{
    smtp.Send(message);
}
Posted
Updated 26-Feb-19 6:52am
Comments
[no name] 24-Feb-19 21:42pm    
What does Google have to do with it? I use SMTP2GO. Just me and them.
RobScripta 25-Feb-19 1:29am    
SMTP2GO has a free plan for 1000 emails/month. I'm between 1000 and 2000 emails/month. Their 20.000/month plan is $14 while I currently pay € 4,= for google.
Maciej Los 25-Feb-19 3:27am    
I've set up the app specific passwords. 

Let me guess... you're storing a password to gmail account in a code - as a plain text, am i right?
If yes, don't be shocked. It's quite easy to get it from executable...
RobScripta 25-Feb-19 15:57pm    
You're right it's shockingly simple to retrieve a password from the IL with ildasm, so that's why I've built a webservice to retrieve passwords and store them locally in a secure string. So this is not my question.

 
Share this answer
 
Comments
RobScripta 26-Feb-19 16:03pm    
Thanks for your thoughts. I found this very helpful comment from Roshan Parmar on several places, and I tried to follow:
solution 2 for case 2:(see https://stackoverflow.com/a/9572958/52277) enable two-factor authentication (aka two-step verification) , and then generate an application-specific password. Use that newly generated password to authenticate via SMTP.
But unfortunately that doesn't work.
Have you followed the various configuration steps?

SMTP relay: Route outgoing non-Gmail messages through Google - G Suite Admin Help[^]

One thing I can see right off the bat is that you're not using the smtp server detailed in the documentation so I'd make sure you've gone through the documentation thoroughly first, and obviously that you are subscribed to a service that allows relaying (sending "from" your own domain).
 
Share this answer
 
Comments
RobScripta 26-Feb-19 16:35pm    
Thanks for your feedback. However when I read the link I think it's about redirecting an SMTP server to Gmail server (pc-->smtp server-->gmail server-->recipient server).
However the route will be pc-->gmail server-->recipient server.
I did try to setup the gsuite for relaying, but I think I won't be able to: We recommend that you configure your mail server to present a unique identifier (such as your domain name or the name of your mail server) in the HELO or EHLO command in the SMTP relay connections your server makes to Google. Avoid using generic names such as "localhost" or "smtp-relay.gmail.com," which can occasionally result in issues with DoS limits.
Another problem is I want to send several dozen reminder emails every morning and: The maximum number of total recipients allowed per customer in a 10-minute window is approximately 9 times the number of user licenses in your G Suite account.
As I have only one user licence i would have to spread them over about an hour!

I really am glad with the feedback, even if I can't get it to work I will still have learned something!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900