'How to sending email in C# without entering password? [closed]

How do you send an email without entering a password?

I made this:

client.Port = 587;
client.Host = "smtp.gmail.com";
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = true;
client.EnableSsl = true;
MailMessage mail = new MailMessage();
mail.From = new MailAddress(emailtxt.Text.Trim());
mail.To.Add("[email protected]");
mail.Subject = "test";
mail.Body = "test";
mail.IsBodyHtml = true;
client.Send(mail);

Is it possible to send an email to Gmail without an authorization? If not, are there any better alternatives?

Less secure apps are off.



Solution 1:[1]

Is it possible to send an email to Gmail without an authorization?

No

If not, are there any better alternatives?

As Mason mentions in the comments, the main alternatives are:

  1. Use a mailto-link to open the users default email program to send the message. This will obviously reveal the email address, but presumably this would happen anyway if you reply to their email.
  2. Setup a simple web-api that receives messages from your application and forwards them to an internal smtp server, or some other system to handle messages. If you want to reply to the user using email you would need to ask him/her for their email address. If you want to ensure the email is correct you could send an automated verification email to the address, and only forward the message once the address has been verified.

There is no real way getting around the need for authentication on the modern internet. The modern way of dealing with this in automated systems would typically be with certificates and API-keys, but email is a quite old protocol with more limited authentication methods.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JonasH