Mail Sending with Network Credential as True in Windows Form Not Working

Cannot send email with SMTP in Windows Forms

I was able to make your code work by adding the following three lines and making change in the gmail account setting:

        client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential (from, password);

In addition to the above changes, it turns out, you also need to update your google account settings and allow less secure apps.

I learned about this on this thread: Sending email in .NET through Gmail

Hope this helps.

winforms not sending mail to gmail with credentials from app.config

Thank you guys, for making attempts to help me. I got it resolved by removing these lines from the code:

    client.EnableSsl = true;
client.UseDefaultCredentials = false;

and changed the <network/> in app.config as follows

<network host="smtp.gmail.com" userName="xyz@gmail.com" password="app_specific_password" port="587" enableSsl="true"/>

Then, it worked

.NET : Unable to change from in SMTP email

I found out that it works when sending the email to my personal Gmail. Meaning that there is nothing wrong with the code, but a configuration problem in my office365 / AD domain.

Apparently the outlook "address book" automatically fills in the "from / sender" part in the email, caused because I was sending an mail to the same domain as the one used for my SMTP account. (for example me@domain-a.com and noreply@domain-a.com).

Sending Email in C# does not work

Did you verify that all the values getting passed in are valid? Possible things to check are host/port. Also, are the 'from' and 'to' getting valid email addresses? Those look a little suspect.

Why is MailMessage sent to any address from Windows Forms application, but not from ASP.NET application, when both are using the same SMTP-server?

This most definitely sounds like an authentication issue or, you are accidently using 2 different SMTP servers.

I recommend you enable logging in both applications, and view the log. When you view the log, you should be able to see the differences, and hopefully trace it back to your code.

To enalbe logging in System.Net.Mail, you need to add some entries to your .config file.

<configuration>
<system.diagnostics>
<trace autoflush="true" />

<sources>

<source name="System.Net" >
<listeners>
<add name="MyTraceFile"/>
</listeners>
</source>

<source name="System.Net.Sockets">
<listeners>
<add name="MyTraceFile"/>
</listeners>
</source>

</sources>

<sharedListeners>
<add
name="MyTraceFile"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="System.Net.trace.log" />
</sharedListeners>

<switches>
<add name="System.Net" value="Verbose" />
<add name="System.Net.Sockets" value="Verbose" />
</switches>
</configuration>

Here is a link with more info:

http://systemnetmail.com/faq/4.10.aspx

The message can not reach the email


The server response was: 5.5.1 Authentication

Based on this error.you check the following steps.

  • Enter the correct login password.
  • To remove 2-Step Verification.
  • You have to enable login from other timezone / ip for your google
    account.To do this follow the click here
    and allow access by clicking the continue button.
  • Go to security settings at the following Click here and enable less secure apps . So that you will be able to login from all apps.


Related Topics



Leave a reply



Submit