Can I send emails without authentication on an SMTP server?

I am creating a simple email application. In my application, when I send an email, I have to enter my email address or password, but I do not want to use a password, I only want to put an email.

So

Is it possible to send email without using a password using the C # / app. net?

this is my code:

try { // setup mail message MailMessage message = new MailMessage(); message.From = new MailAddress(textBox1.Text); message.To.Add(new MailAddress(textBox2.Text)); message.Subject = textBox3.Text; message.Body = richTextBox1.Text; // setup mail client SmtpClient mailClient = new SmtpClient("smtp.gmail.com"); mailClient.Credentials = new NetworkCredential(textBox1.Text,"password"); // send message mailClient.Send(message); MessageBox.Show("Sent"); } catch(Exception) { MessageBox.Show("Error"); } 
+4
source share
2 answers

Is it possible to send email without using a password using the C # / app. net?

Yes, if you have access to a mail gateway that does not require authentication, you can simply:

 SmtpClient mailClient = new SmtpClient("your.emailgateway.com"); mailClient.Send(message); 

Perhaps your company or Internet service provider can provide you this service?

+2
source

In general, you can, of course. In your specific code example, you are using GMail, which does not allow anonymous submission.

From their link :

smtp.gmail.com (use authentication)
Use Authentication: Yes
Port for TLS / STARTTLS: 587
Port for SSL: 465

Additional comment regarding your catch clause:

In my opinion, you greatly abuse the idea of ​​exclusion. A better aproach would be something like:

 catch(Exception x) { var s = x.Message; if ( x.InnerException!=null ) { s += Environment.NewLine + x.InnerException.Message; } MessageBox.Show(s); } 
+2
source

Source: https://habr.com/ru/post/1434998/


All Articles