How to Send an Email in .Net According to New Security Policies

How to send an email in .Net according to new security policies?

The general solution is https://galleryserverpro.com/use-gmail-as-your-smtp-server-even-when-using-2-factor-authentication-2-step-verification/

1) Use a browser to log in to your Google account and go to your Sign-in & security settings. Look for the 2-step verification setting.

2) If 2-step verification is off and you want to keep it that way that's mean that you will need to implement many auth mechanism as you said.

Solution: Turn it on and then generate and use google app password. It should work! You don't need to use other libraries like mailkit.

Cannot send emails through ASP.NET application

I managed to find a solution to my original question. Instead of sending directly from my application, I set up my SMTP server to use a pickup directory instead.

The application code is very simple now, specifying the delivery method and pickup directory can also be moved into the configuration file.

SmtpClient client = new SmtpClient("localhost", 25);
client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
client.PickupDirectoryLocation = @"C:\inetpub\mailroot\Pickup";
client.Send(mail);

Another advantage with this approach is that the generation of emails from the application can be tested without setting up SMTP on a development machine. By looking in the pickup directory you can determine if the application is working correctly.

Using this approach on my live server, I receive the email almost as soon as I send it from my application so the performance is very good.

The SMTP server requires a secure connection or the client was not authenticated. if uploading on godaddy

you should enable application to access gmail account. This link will help you

Sending email in .NET through Gmail

Be sure to use System.Net.Mail, not the deprecated System.Web.Mail. Doing SSL with System.Web.Mail is a gross mess of hacky extensions.

using System.Net;
using System.Net.Mail;

var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@example.com", "To Name");
const string fromPassword = "fromPassword";
const string subject = "Subject";
const string body = "Body";

var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}

Additionally go to the Google Account > Security page and look at the Signing in to Google > 2-Step Verification setting.

  • If it is enabled, then you have to generate a password allowing .NET to bypass the 2-Step Verification. To do this, click on Signing in to Google > App passwords, select app = Mail, and device = Windows Computer, and finally generate the password. Use the generated password in the fromPassword constant instead of your standard Gmail password.
  • If it is disabled, then you have to turn on Less secure app access, which is not recommended! So better enable the 2-Step verification.

Can I send SMTP email through Office365 shared mailbox?

  1. Yes, you can.

  2. Usersettings:
    Screenshot of Admin Center
    Screenshot of Manage email apps

Server-settings :
https://support.office.com/en-us/article/POP-IMAP-and-SMTP-settings-for-Outlook-com-d088b986-291d-42b8-9564-9c414e2aa040

SMTP server name smtp.office365.com

SMTP port 587

SMTP encryption method STARTTLS

  1. No, you cannot. You need a licenced user to send mail via SMTP.

https://answers.microsoft.com/en-us/msoffice/forum/msoffice_o365admin/set-up-smtp-relay-with-shared-mailbox/d7b98214-9564-432c-b098-525a98c529fb

A customer of ours has a newsletter system set up with TYPO3 and we had to create a new mailbox for this. However, a light one will suffice: instead of a Office 365 Business Premium we only assigned a Office 365 F1 licence.

Edit: also found this: Can Office365 shared mailbox use SMTP?

Best practice to send secure information over e-mail?

The best course of action would be to run the other way, fast. Redesign your application so that it doesn't enable identity theft.

You can use S/MIME or PGP to send secure email to most non-Web email clients, but it takes a lot of set up either way: the recipient has to have a certificate, and you have to get the right certificate for each recipient.


As an example of a better design, consider one where the recipient is mailed a notification, and then returns to the web site to view the information after authenticating securely over SSL.

While it helps to reduce the complexity of the system needed by the recipient, the bigger win is that it strengthens control over the distribution and retention of the sensitive information, and aids in auditing the access to that information. Sending someone an email makes it that much easier for them to store it unsafely, forever, or forward it to unauthorized recipients.



Related Topics



Leave a reply



Submit