locked
Email RRS feed

  • Question

  • User-1499457942 posted

    Hi

      What is the best way to send secure Email using c#

    Thanks

    Tuesday, June 19, 2018 10:57 AM

Answers

  • User-762312836 posted

    As well as the obvious checking you're using correct credentials as others have stated, it is likely you will need to enable the 'Allow less secure apps' feature.

    You can enable it by logging into your gmail account, clicking your name badge, choose 'My Account', click 'Apps with account access', and click the slider for 'Allow less secure apps' to enable it. 

    It might be worth explicitly setting the port, too (587 I think).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 19, 2018 7:08 PM

All replies

  • User475983607 posted

    Hi

      What is the best way to send secure Email using c#

    Thanks

    A forum cannot answer this question, contact your email provider and ask. 

    C# has API for sending email, SmtpClient, and SmtpClient can send secured email over TLS but email security is in the hands of the email provider. Anyway, SMTP in .NET is an openly published with abundant examples.

    https://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient(v=vs.110).aspx

    Or you can use an API like SendGrid.

    https://sendgrid.com/marketing/sendgrid-services-cro/?var=3&cvosrc=PPC.Google.sendgrid&cvo_cid=SendGrid%20-%20US%20-%20Brand%20-%20(English)&mc=Paid%20Search&mcd=AdWords&keyword=sendgrid&network=g&matchtype=e&mobile=&content=&search=1&gclid=CjwKCAjw06LZBRBNEiwA2vgMVX5xKzbg4rVwTluoaqE9bzqYvCXs3MEDYjA7kQaQUNgAkcoZeWPxXxoCNIkQAvD_BwE

    Try to do a bit of research first...

    Tuesday, June 19, 2018 11:13 AM
  • User753101303 posted

    Hi,

    "Secure" is a bit vague. What do you want to prevent exactly ? If you meant that you want to encrypt the message try https://dougrathbone.com/blog/2009/10/02/sending-encrypted-email-with-c as well as https://www.ablebits.com/office-addins-blog/2014/04/11/email-encryption-outlook/ which might give a better overview of the whole process.

    Tuesday, June 19, 2018 11:27 AM
  • User-1499457942 posted

    Hi

      I have written the below code but i am getting this error - The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

    string smtpAddress = "smtp.gmail.com";
    int portNumber = 587;
    bool enableSSL = true;

    string emailFrom = "tst@gmail.com";
    string password = "test";
    string emailTo = "test@yahoo.com";
    string subject = "Hello";
    string body = "Hello, I'm just trying to send emal Hi!";

    using (MailMessage mail = new MailMessage())
    {
    mail.From = new MailAddress(emailFrom);
    mail.To.Add(emailTo);
    mail.Subject = subject;
    mail.Body = body;
    mail.IsBodyHtml = true;
    using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
    {
    smtp.Credentials = new NetworkCredential(emailFrom, password);
    smtp.EnableSsl = enableSSL;
    smtp.Send(mail);
    }
    }

    Thanks

    Tuesday, June 19, 2018 11:55 AM
  • User753101303 posted

    Log to the gmail box.

    Assuming credentials are correct, when a gmail account is used from an unusual location, gmail pick that and may refuse the connection. You should have a mail that explain how to disable this safety check.

    If you don't see this could it be that credentials are really wrong ?

    Tuesday, June 19, 2018 12:20 PM
  • User475983607 posted

    I have written the below code but i am getting this error - The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

    Contact gmail support for gmail support.

    Tuesday, June 19, 2018 1:43 PM
  • User-762312836 posted

    As well as the obvious checking you're using correct credentials as others have stated, it is likely you will need to enable the 'Allow less secure apps' feature.

    You can enable it by logging into your gmail account, clicking your name badge, choose 'My Account', click 'Apps with account access', and click the slider for 'Allow less secure apps' to enable it. 

    It might be worth explicitly setting the port, too (587 I think).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 19, 2018 7:08 PM