Copied to clipboard

Flag this post as spam?

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


  • Stefan 10 posts 30 karma points
    Feb 11, 2010 @ 17:59
    Stefan
    0

    SendMail from datatype?

    Hi

    I am having some trouble sending emails from within a datatype.

    In my datatype I have the save event and the oninit event.

    In the oninit event I create a button and its click event and add the button to the base.controls.

    when clicked i use umbraco.library.sendmail function in the event.

    But I get no email ?

    The funny thing is that i have some extension methods which is also using umbraco.library.sendmail with the same parameters, they are totally identical and when used here i receive the emails but not when it is inside a custom datatype.

     

    Any ideas ?

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Feb 11, 2010 @ 19:42
    Sebastiaan Janssen
    0

    Not a clue, but hit the debug button in Visual Studio and find out what's going wrong. Also, try and have a look in the umbracoLog table or your windows event log to see any errors, surely there must be something there.

  • Stefan 10 posts 30 karma points
    Feb 17, 2010 @ 13:06
    Stefan
    0

    Alright got the sendmail to work!

    I got another problem now.

    In my datatype i render a textbox - in this textbox i can write a number ex. 5 - when i then hit save and publish i get some information from 5 users which is then saved on the <data> on the node holding the datatype.

    So when i save and publish my textbox goes away and i render a <table> with the information and a button which can be clicked and sends out an email to the 5 users.

    The problem is that when i hit the button to send the email after i have clicked save and publish it does not send anything but when i hit it the second time it goes into my click event and sends out the emails.

    Any ideas? I think it got something to do when i create my button in the code.

    Is it possible to overrinde onload / onprerender in my datatype ? Right now i have the save and oninit event.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 17, 2010 @ 15:29
    Jan Skovgaard
    0

    Is it possible that you could might share some of your code? I think it would make it a bit easier to help you out?

    I'm not sure what you are trying to achieve with the stuff you're working at - But I'm think that you could maybe achieve your goal by using the MailEngine created by Tim Geysens? It can be found here: http://www.nibble.be/?p=63 - And it's just a proposal :-)

    /Jan

  • Stefan 10 posts 30 karma points
    Feb 18, 2010 @ 10:22
    Stefan
    0

    I got it to work even though it is not pretty!

    I cant use OnLoad og OnPreRender. OnPreRender is actually what i need, so i can have my AddControls() there. However it doesnt work!

    It goes like this, have deleted some code, to shorten it down, it was just where i had string concat to my winnerTable.

    protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);

                _emailButton = new Button();
                _emailButton.Text = "Send email";
                _emailButton.Click += new EventHandler(button_Click);

                AddControls(this._data.Value.ToString(), _emailButton);
            }

    private void AddControls(string data, Button button)
            {
                if (data.Length > 0)
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(data);

                    XmlNodeList nodes = doc.GetElementsByTagName("winners");
                    bool emailSent = false;


                    foreach (XmlNode node in nodes)
                    {
                        if (!string.IsNullOrEmpty(node.Attributes["email"].Value))
                        {
                              emailSent = Convert.ToBoolean(node.Attributes["email"].Value;
                        }
                    }

                    List<Winner> winners = Helper.ConvertXMLToList(data);
                    FastString winnerTable = string.Empty;

                    if (winners.Count > 0)
                    {
                       // winnerTable concat here
                        if (!emailSent)
                        {
                            // winnerTable concat button
                            base.Controls.Add(new LiteralControl(winnerTable));
                            base.Controls.Add(button);
                            base.Controls.Add(new LiteralControl(winnerTable));
                        }
                        else
                        {
                            //winnerTable end concat
                            base.Controls.Add(new LiteralControl(winnerTable));
                        }
                    }
                    else
                    {
                        TextBox winnerCount = new TextBox();
                        winnerCount.ID = "WinnerCountTextBox";

                        base.Controls.Add(new LiteralControl("<div style=\"font-weight:bold;\">"));
                        base.Controls.Add(new LiteralControl("Antal vindere"));
                        base.Controls.Add(new LiteralControl("</div>"));

                        base.Controls.Add(new LiteralControl("<div>"));
                        base.Controls.Add(winnerCount);
                        base.Controls.Add(new LiteralControl("</div>"));
                    }
                }
                else
                {
                    this._data.Value = Helper.ConvertListToXML(new List<Winner>(), false);

                    TextBox winnerCount = new TextBox();
                    winnerCount.ID = "WinnerCountTextBox";

                    base.Controls.Add(new LiteralControl("<div style=\"font-weight:bold;\">"));
                    base.Controls.Add(new LiteralControl("Antal vindere"));
                    base.Controls.Add(new LiteralControl("</div>"));

                    base.Controls.Add(new LiteralControl("<div>"));
                    base.Controls.Add(winnerCount);
                    base.Controls.Add(new LiteralControl("</div>"));
                }
            }

    public void Save()
            {
                TextBox winnerCount = null;
                foreach (Control childControl in base.Controls)
                {
                    if (childControl is TextBox)
                    {
                        if (childControl.ID == "WinnerCountTextBox")
                        {
                            winnerCount = (TextBox)childControl;
                            break;
                        }
                    }
                }

                if (winnerCount != null)
                {
                    if (!string.IsNullOrEmpty(winnerCount.Text.Trim()))
                    {
                        int pageid = Convert.ToInt32(HttpContext.Current.Request["id"]);
                        List<Winner> winners = new List<Winner>();
                        winners = Helper.GetRandomWinners(pageid, Convert.ToInt32(winnerCount.Text.Trim()));
                        this._data.Value = Helper.ConvertListToXML(winners, false);

                        HttpContext.Current.Response.Redirect(HttpContext.Current.Request.Url.ToString()); <----- THIS MAKES IT WORK! BUT IT IS NOT PRETTY
                    }
                }
            }

    void button_Click(object sender, EventArgs e)
            {

                //Send email to the winners

            }

     

    I do have a little problem well not a problem but a little issue. When I get my winners and save the data gets saved on the node but when i go look in the cmsContentXml table i cant see the actual data - but its there casue the node is displaying in fine. Dont know what it i might be.

     

     

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft