Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Pinal Bhatt 298 posts 390 karma points
    Feb 08, 2011 @ 20:24
    Pinal Bhatt
    0

    How to send email via secure connection?

    Hello Umbraco Community,

    I am getting following error while sending email via following xslt:

    <xsl:value-of select="umbraco.library:SendMail('[email protected]', '[email protected]', 'String Subject', 'String Body', 'true')"/>

    umbraco.library.SendMail: Error sending mail. Exception: System.Net.Mail.SmtpException: 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. p32sm2206028ybk.8 at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at umbraco.library.SendMail(String FromMail, String ToMail, String Subject, String Body, Boolean IsHtml)

    How to send email via secure connection?


  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 08, 2011 @ 21:22
    Jan Skovgaard
    0

    Hello Pinal

    Have you setup the SMTP information i the web.config at all?

    /Jan

  • Pinal Bhatt 298 posts 390 karma points
    Feb 08, 2011 @ 21:24
    Pinal Bhatt
    0

    Yes smtp setting are fine in web.config

     <system.net>
        <mailSettings>
          <smtp>
            <network host="smtp.gmail.com" userName="[email protected]" password="xxxxxx" port="587" />
          </smtp>
        </mailSettings>
      </system.net>

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 08, 2011 @ 21:33
    Jan Skovgaard
    0

    Hi Pinal

    Maybe this could have something to do with the settings in google apps?

    Try reading this answer here - I think part 1 could be worth checking out: http://www.google.com/support/forum/p/Google%20Apps/thread?tid=396e53acd0030ef4&hl=en

    /Jan

  • Pinal Bhatt 298 posts 390 karma points
    Feb 08, 2011 @ 21:38
    Pinal Bhatt
    2

    I don't think any issue with google.

    I was looking at code in umbraco.library.SendMail

    public static void SendMail(string FromMail, string ToMail, string Subject, string Body, bool IsHtml)
    {
        try
        {
            MailMessage message = new MailMessage(FromMail.Trim(), ToMail.Trim());
            message.Subject = Subject;
            if (IsHtml)
            {
                message.IsBodyHtml = true;
            }
            else
            {
                message.IsBodyHtml = false;
            }
            message.Body = Body;
            new SmtpClient().Send(message);
        }
        catch (Exception exception)
        {
            Log.Add(LogTypes.Error, -1, string.Format("umbraco.library.SendMail: Error sending mail. Exception: {0}", exception));
        }
    }
    

    Looks Umbraco library is not taking care of enabling SSL.

    I modifed the code as below and is working fine.

     public static void SendMail(string FromMail, string ToMail, string Subject, string Body, bool IsHtml)
            {
                try
                {
                    MailMessage message = new MailMessage(FromMail.Trim(), ToMail.Trim());
                    message.Subject = Subject;
                    if (IsHtml)
                    {
                        message.IsBodyHtml = true;
                    }
                    else
                    {
                        message.IsBodyHtml = false;
                    }
                    message.Body = Body;
                    SmtpClient client = new SmtpClient();
                    client.EnableSsl = true;
                    client.Send(message);
                    
                }
                catch (Exception exception)
                {
                    Log.Add(LogTypes.Error, -1, string.Format("PBDesk.Umbraco.Helper.UmbHelper.SendMail: Error sending mail. Exception: {0}", exception));
                }
            }

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 08, 2011 @ 21:40
    Jan Skovgaard
    0

    Hi Pinal

    ah yes of course, my bad..you needed to be able to send using SSL...

    Oh well, nice that you got it fixed and posted the solution for future reference other can benefit from :-)

    /Jan

  • Pinal Bhatt 298 posts 390 karma points
    Feb 09, 2011 @ 17:59
    Pinal Bhatt
    0

    Can we suggest Umbraco dev team to add one more overload for umbraco.library.SendMail method to take parameter for enabling SSL?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 09, 2011 @ 18:05
    Jan Skovgaard
    0

    Hi Pinal

    You can add a feature suggestion on codeplex if you think this extension should be modified. However I'm not sure they will change the extension. But maybe this could be a great suggestion for the uComponents package? Maybe you could contribute to that project because there is no doubt about it's a good idea :-)

    /Jan

  • Pinal Bhatt 298 posts 390 karma points
    Apr 04, 2011 @ 15:54
    Pinal Bhatt
    1

    Hi 

    Below is my XSLT/Macro solution for sending emails from Umbraco via SSL.

    Assumning smtp settings done properly in web.config as below:

     

     <system.net>
       
    <mailSettings>
         
    <smtp>
           
    <network host="smtp.gmail.com" userName="[email protected]" password="xxxxxx" port="587" />
         
    </smtp>
       
    </mailSettings>
     
    </system.net>

     

    SecuredEmailViaXSLT.xslt
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
      version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:mycslib="urn:mycslib" 
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" xmlns:ucomponents.cms="urn:ucomponents.cms" xmlns:ucomponents.dates="urn:ucomponents.dates" xmlns:ucomponents.io="urn:ucomponents.io" xmlns:ucomponents.media="urn:ucomponents.media" xmlns:ucomponents.members="urn:ucomponents.members" xmlns:ucomponents.nodes="urn:ucomponents.nodes" xmlns:ucomponents.search="urn:ucomponents.search" xmlns:ucomponents.strings="urn:ucomponents.strings" xmlns:ucomponents.urls="urn:ucomponents.urls" xmlns:ucomponents.xml="urn:ucomponents.xml" 
      exclude-result-prefixes="msxml mycslib umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary ucomponents.cms ucomponents.dates ucomponents.io ucomponents.media ucomponents.members ucomponents.nodes ucomponents.search ucomponents.strings ucomponents.urls ucomponents.xml ">
    
    
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <msxml:script implements-prefix="mycslib" language="C#">
    <msxml:assembly name="System"/>
    <msxml:using namespace="System.Web"/>  
    
        <![CDATA[
    
          public void SendMail(string FromMail, string ToMail, string Subject, string Body, bool IsHtml)
            {
                try
                {
                    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(FromMail.Trim(), ToMail.Trim());
                    message.Subject = Subject;
                    if (IsHtml)
                    {
                        message.IsBodyHtml = true;
                    }
                    else
                    {
                        message.IsBodyHtml = false;
                    }
                    message.Body = Body;
                    System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
                    client.EnableSsl = true;
                    client.Send(message);
    
                }
                catch (Exception exception)
                {
                    //umbraco.BusinessLogic.Log.Add(LogTypes.Error, -1, string.Format("PBDesk.Umbraco.Helper.UmbHelper.SendMail: Error sending mail. Exception: {0}", exception));
                }
            }
    
        ]]>
    </msxml:script>     
    
    <xsl:param name="currentPage"/>
    
    <xsl:template match="/">
    
    <xsl:value-of select="mycslib:SendMail('[email protected]', '[email protected]', 'String Subject', 'String Body', 'true')"/>
    
    
    </xsl:template>
    
    </xsl:stylesheet>

    Thanks & Regards,

    Pinal Bhatt

     

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 04, 2011 @ 16:15
    Lee Kelleher
    0

    Hi Pinal,

    One bit of advice, try not to use the inline code/script blocks within your XSLT files.  As they are compiled for each and every page load (and stored on your server's temp folder).  If possible, move the code to an App_Code class. (or even better a separately compiled assembly).

    More info on the XSLT code issue: http://www.tkachenko.com/blog/archives/000620.html

    ... and Doug has a blog post on how he moved his XSLTsearch code over to App_Code: http://blog.percipientstudios.com/2010/11/12/make-an-app_code-xslt-extension-for-umbraco.aspx

    Cheers, Lee.

  • Solea Razvan 1 post 21 karma points
    Apr 04, 2011 @ 23:53
    Solea Razvan
    0

    This is an awesome exercise for someone like me new to this kind of CMS.

    Nice advice Lee !

    Thank you Pinal, your support is much appreciated.

    Umbraco comunity looks better and better to a newbie like me ;)

  • Daniel Bardi 927 posts 2562 karma points
    Apr 05, 2011 @ 06:55
    Daniel Bardi
    0

    You're beginning to see the orange light!

Please Sign in or register to post replies

Write your reply to:

Draft