Unable to send email to receiver using mail Target

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Unable to send email to receiver using mail Target

Deepa Samota
I'm working with nLog for the first time and all's well except for Email.
For some reason I am always getting exception.[The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. 20sm3729730pzk.13"]
My environment is .net 3.5, Visual Studio 2008.
Is there anything in the way the target or rules are set up that could be giving me problems.

<?xml version="1.0" encoding="utf-8" ?>
<configuration> 
    <configSections> 
        <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/> 
    </configSections> 
    <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

        <targets> 
              <target name="mail" xsi:type="Mail" smtpServer="smtp.gmail.com"
                from="xyz@gamil.com" to="abc@gmail.com"
                subject="test mail" HTML="true" Encoding="UTF8" smtpAuthentication="Basic" smtpPassword="secret" smtpUsername="xyz@gamil.com"  port="465"/>
    </targets>
        </targets> 
        <rules> 
            <logger name="*" level="Info" writeTo="mail"/> 
        </rules> 
    </nlog> 

</configuration> 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to send email to receiver using mail Target

Jarek Kowalski
Administrator
This is a known issue - NLog 1.0 does not support SSL for Mail and GMail requires that. It is supported in NLog 2.0, but it's not ready/recommended for production usage yet.
 
There's relatively easy fix for that which requires you to modify and recompile NLog sources (which is relatively easy to do):
 
1. Dowload and unpack NLog sources
2. Edit src\NLog\Targets\Mail,cs
3. Add a boolean property called EnableSsl to the class:
 
        [DefaultValue(false)]
        public bool EnableSsl { get; set; }
 
4. Find the following 2 lines:
            Internal.InternalLogger.Debug("Sending mail to {0} using {1}", msg.To, _smtpServer);
            client.Send(msg);
 
and insert this line just before client.Send(msg) so that it reads
 
            Internal.InternalLogger.Debug("Sending mail to {0} using {1}", msg.To, _smtpServer);
            client.EnableSsl = this.EnableSsl;  // added code
            client.Send(msg);
 
5. Compile NLog - you should now have new option at your disposal.
 
Just add enableSsl="true" to your target declaration and you should be able to send mail using GMail
 
Jarek
 
 
On Mon, Jan 25, 2010 at 4:25 AM, Deepa Samota [via NLog Forum] <[hidden email]> wrote:
I'm working with nLog for the first time and all's well except for Email.
For some reason I am always getting exception.[The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. 20sm3729730pzk.13"]
My environment is .net 3.5, Visual Studio 2008.
Is there anything in the way the target or rules are set up that could be giving me problems.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
    </configSections>
    <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

        <targets>
              <target name="mail" xsi:type="Mail" smtpServer="smtp.gmail.com"
                from="[hidden email]" to="[hidden email]"
                subject="test mail" HTML="true" Encoding="UTF8" smtpAuthentication="Basic" smtpPassword="secret" smtpUsername="[hidden email]"  port="465"/>
    </targets>
        </targets>
        <rules>
            <logger name="*" level="Info" writeTo="mail"/>
        </rules>
    </nlog>

</configuration>


View message @ http://n2.nabble.com/Unable-to-send-email-to-receiver-using-mail-Target-tp4453654p4453654.html
To start a new topic under NLog Forum, email [hidden email]
To unsubscribe from NLog Forum, click here.


NLog Blog
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to send email to receiver using mail Target

RoryBecker
Hi Jarek.

I've also tried the above with, I'm sad to say... Not much luck. :(

I wonder is 2.0 any nearer to what you might consider production ready. If not, perhaps you could indicate where it is lacking.

Thanks very much in advance :)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to send email to receiver using mail Target

RoryBecker
Ok never mind me.. I have now got this to work. PEBKAC :(

Although I would still be interested in learning what is and isn't ready in 2.0 and some sort of general time scale.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to send email to receiver using mail Target

Basil
Hi Rory,

I'd like to know how you got this to work. I've made the same source changes and it would appear that I am missing something.

Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to send email to receiver using mail Target

Rory Becker
IIRC it was something to do with deployment. I think I was referencing an older version of the library rather than the one I had just recompiled.

Assuming that your lib is compiling correctly, check that you're copying the binary to the correct location and that there is no sign of the older version. I typically check modified dates as well as version numbers to confirm this.
Also check that you've not added an version of NLog to the GAC where it might be picked up in preference.

Just a few random ideas

--
Rory Becker
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to send email to receiver using mail Target

Anand Patel
In reply to this post by Jarek Kowalski
Hi Jarek,

We are using NLog 2.0 released on 17th July 2011 with .Net Framework 4.0. We are still unable to send email using Gmail id. So do we need to apply same fix which you suggested in current version of NLog 2.0 ?

Please reply me on anand.patel@enthalpysystems.co.in , will wait for your reqply.

Thanks in Advance.

With Best Regards,

Anand Patel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to send email to receiver using mail Target

Anand Patel
Hi Jarek,

I got the solution, I download latest source from https://nodeload.github.com/jkowalski/NLog/zipball/master 

Extract the zip folder and go into src folder and open solution for .net framework 4.0 e.g. NLog.netfx40.sln and build the solution to generate NLog.dll. After build the solution i found its .dll inside build\bin\Debug\.NET Framework 4.0 folder of above unziped folder.
I copy that NLog.dll and and paste it in my application package directory and add referance in project by locating this latest NLog.dll


After doing this i try to generate user defined exception and received email from my gmail account. If anyone need further help then let me know.

Many Thanks

With Best Regards,

Anand Patel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to send email to receiver using mail Target

Sharda
I tried the same solution but still I am not able to send log to email target. I made below settings in the config file..

    <target name="mail"
            xsi:type="Mail"
            smtpServer="smtp.gmail.com"
            from="username1@gmail.com"
            to="username2@hotmail.com"
            subject="test mail"
            smtpAuthentication="Basic"
            smtpPassword="secret"
            smtpUserName="username1@gmail.com"  
            smtpPort="465"/>

Are the above settings incorrect?

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to send email to receiver using mail Target

Sharda
Hi Anand,

I am still not able to send the message from my gmail account.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to send email to receiver using mail Target

Janus Knudsen
I use this.. it works :)

    <target name="Email" xsi:type="Mail"
            smtpServer="smtp.gmail.com"
            smtpPort="587"
            smtpAuthentication="Basic"
            smtpUsername="ddd@gmail.com"
            smtpPassword="dddb123"
            enableSsl="true"
            from="qwerty@gmail.com"
            to="ddd@gmail.com"
            layout="${longdate}|${level:uppercase=true}|${logger}|${message}|${exception}"
          />
Yug
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to send email to receiver using mail Target

Yug
I tried the configurations mentioned above and also can't get this to work.  No errors appear, but no email is sent/recieved.  My environment is Nlog 2.0, .Net framework 4.0, visual studio express.  Appreciate any suggestions.  Thanks!
Yug
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to send email to receiver using mail Target

Yug
Now working. Not sure that i changed anything significant since yesterday, but i did restart, maybe that triggered something.
Loading...