Contact us Conlib

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
Richard47
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 47
Joined: Thu Nov 04, 2010 1:15 pm

Contact us Conlib

Post by Richard47 » Tue Sep 25, 2012 4:55 pm

We are using this Conlib File on our Able 7.7 version. Tried using it on the Gold version but it is not working for some reason any help please. Thanks in advance.

<%@ Control Language="C#" ClassName="ContactUs" %>
<script runat="server">
private string _sendTo;
public string SendTo
{
get { return _sendTo; }
set { _sendTo = value; }
}

protected void SendButton_Click(object sender, EventArgs e)
{
Store store = Token.Instance.Store;
StoreSettingCollection settings = store.Settings;
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();

if (String.IsNullOrEmpty(SendTo))
{
mailMessage.To.Add(settings.DefaultEmailAddress);

}
mailMessage.From = new System.Net.Mail.MailAddress(Email.Text);
mailMessage.Subject ="Feedback";
mailMessage.Body += "Name: "+Name.Text+Environment.NewLine;
mailMessage.Body += "Email: " + Email.Text + Environment.NewLine;
mailMessage.Body += "Phone: "+Phone.Text+Environment.NewLine;
mailMessage.Body += "Product: "+Product.Text+Environment.NewLine;
mailMessage.Body += "Comment: "+Environment.NewLine+Comment.Text;
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
mailMessage.IsBodyHtml = false;
mailMessage.Priority = System.Net.Mail.MailPriority.High;
SmtpSettings smtpSettings = SmtpSettings.DefaultSettings;

try
{
MessageLabel.Text = "Message Sent";
MessageLabel.CssClass = "goodCondition";
EmailClient.Send(mailMessage);
}
catch (Exception exp)
{
MessageLabel.Text = exp.Message;
MessageLabel.CssClass = "errorCondition";
}
}
</script>

<table cellpadding="0" cellspacing="0" class="inputForm">
<tr>
<th style="text-align:right;padding-right:3px;">
Name</th>
<td>
<asp:TextBox ID="Name" runat="server" ValidationGroup="ContactUs"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Name"
ErrorMessage="Name is Required." ToolTip="Name is Required."
Display="Static" Text="*" ValidationGroup="ContactUs">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<th style="text-align:right;padding-right:3px;">
Email</th>
<td>
<asp:TextBox ID="Email" runat="server" ValidationGroup="ContactUs"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email"
ErrorMessage="Email Address is Required." ToolTip="Email Address is Required."
Display="Static" Text="*" ValidationGroup="ContactUs">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="EmailValidator" runat="server" Display="Static"
ControlToValidate="Email" ValidationExpression="\S+@\S+\.\S+" ErrorMessage="The email address is not properly formatted."
Text="*" ValidationGroup="ContactUs"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<th style="text-align:right;padding-right:3px;">
Phone</th>
<td>
<asp:TextBox ID="Phone" runat="server" ValidationGroup="ContactUs"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorPhone" runat="server" ControlToValidate="Phone"
ErrorMessage="Name is Required." ToolTip="Phone is required."
Display="Static" Text="*" ValidationGroup="ContactUs">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<th style="text-align:right;padding-right:3px;">
Product</th>
<td>
<asp:TextBox ID="Product" runat="server" ValidationGroup="ContactUs"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorProduct" runat="server" ControlToValidate="Product"
ErrorMessage="Name is Required." ToolTip="Product."
Display="Static" Text="*" ValidationGroup="ContactUs">*</asp:RequiredFieldValidator>
</td>
</tr>

<tr>
<th style="text-align:right;padding-right:3px;">
Comment</th>
<td>
<asp:TextBox ID="Comment" runat="server" TextMode="MultiLine" ValidationGroup="ContactUs"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="Comment"
ErrorMessage="Comment is Required." ToolTip="Leave comments or ask questions."
Display="Static" Text="*" ValidationGroup="ContactUs">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="SendButton" runat="server" Text="Send" ValidationGroup="ContactUs" OnClick="SendButton_Click" /></td>
</tr>
<tr>
<td></td>
<td >
<asp:Label ID="MessageLabel" runat="server"></asp:Label>
<asp:ValidationSummary ID="ContactUsSummary" runat="server" ValidationGroup="ContactUs" />
</td>
</tr>
</table>[/code]

User avatar
david-ebt
Captain (CAPT)
Captain (CAPT)
Posts: 253
Joined: Fri Dec 31, 2010 10:12 am

Re: Contact us Conlib

Post by david-ebt » Tue Sep 25, 2012 5:48 pm

Yes, quite a few things changed from 7.0.7 to GOLD. This should get you started. Change the

Code: Select all

Store store = Token.Instance.Store;
StoreSettingCollection settings = store.Settings;
lines to

Code: Select all

Store _store = AbleContext.Current.Store;
StoreSettingsManager _settings = _store.Settings;
The big thing is the Token.Instance is replace by the AbleContext.Current.
David
http://www.ecombuildertoday.com
Enhanced Reporting for AbleCommerce
Image

Richard47
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 47
Joined: Thu Nov 04, 2010 1:15 pm

Re: Contact us Conlib

Post by Richard47 » Tue Sep 25, 2012 5:57 pm

david-ebt wrote:Yes, quite a few things changed from 7.0.7 to GOLD. This should get you started. Change the

Code: Select all

Store store = Token.Instance.Store;
StoreSettingCollection settings = store.Settings;
lines to

Code: Select all

Store _store = AbleContext.Current.Store;
StoreSettingsManager _settings = _store.Settings;
The big thing is the Token.Instance is replace by the AbleContext.Current.
Yeah I have noticed that David. I made the change you mentioned but now I am getting this error in the error log file

Error sending email with subject 'Feedback'.
Exception: A recipient must be specified. Stack Trace: at System.Net.Mail.SmtpClient.Send(MailMessage message) at CommerceBuilder.Messaging.EmailClient.Send(MailMessage mailMessage, SmtpSettings smtpSettings, Boolean throwOnError)

Thanks Richard

User avatar
david-ebt
Captain (CAPT)
Captain (CAPT)
Posts: 253
Joined: Fri Dec 31, 2010 10:12 am

Re: Contact us Conlib

Post by david-ebt » Wed Sep 26, 2012 8:25 am

Richard,

This code worked for me:

Code: Select all

<%@ Control Language="C#" ClassName="ContactUs" %>
<script runat="server"> 
    private string _sendTo;
    public string SendTo
    {
        get { return _sendTo; }
        set { _sendTo = value; }
    }

    protected void SendButton_Click(object sender, EventArgs e)
    {
        Store _store = AbleContext.Current.Store;
        StoreSettingsManager _settings = _store.Settings;

        System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();

        if (String.IsNullOrEmpty(SendTo))
        {
            mailMessage.To.Add(_settings.DefaultEmailAddress);

        }
        mailMessage.From = new System.Net.Mail.MailAddress(Email.Text);
        mailMessage.Subject = "Feedback";
        mailMessage.Body += "Name: " + Name.Text + Environment.NewLine;
        mailMessage.Body += "Email: " + Email.Text + Environment.NewLine;
        mailMessage.Body += "Phone: " + Phone.Text + Environment.NewLine;
        mailMessage.Body += "Product: " + Product.Text + Environment.NewLine;
        mailMessage.Body += "Comment: " + Environment.NewLine + Comment.Text;
        mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
        mailMessage.IsBodyHtml = false;
        mailMessage.Priority = System.Net.Mail.MailPriority.High;
        SmtpSettings smtpSettings = SmtpSettings.DefaultSettings;

        try
        {
            MessageLabel.Text = "Message Sent";
            MessageLabel.CssClass = "goodCondition";
            EmailClient.Send(mailMessage);
        }
        catch (Exception exp)
        {
            MessageLabel.Text = exp.Message;
            MessageLabel.CssClass = "errorCondition";
        }
    }
</script>
<table cellpadding="0" cellspacing="0" class="inputForm">
    <tr>
        <th style="text-align: right; padding-right: 3px;">
            Name
        </th>
        <td>
            <asp:TextBox ID="Name" runat="server" ValidationGroup="ContactUs"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Name"
                ErrorMessage="Name is Required." ToolTip="Name is Required." Display="Static"
                Text="*" ValidationGroup="ContactUs">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <th style="text-align: right; padding-right: 3px;">
            Email
        </th>
        <td>
            <asp:TextBox ID="Email" runat="server" ValidationGroup="ContactUs"></asp:TextBox>
            <asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email"
                ErrorMessage="Email Address is Required." ToolTip="Email Address is Required."
                Display="Static" Text="*" ValidationGroup="ContactUs">*</asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="EmailValidator" runat="server" Display="Static"
                ControlToValidate="Email" ValidationExpression="\S+@\S+\.\S+" ErrorMessage="The email address is not properly formatted."
                Text="*" ValidationGroup="ContactUs"></asp:RegularExpressionValidator>
        </td>
    </tr>
    <tr>
        <th style="text-align: right; padding-right: 3px;">
            Phone
        </th>
        <td>
            <asp:TextBox ID="Phone" runat="server" ValidationGroup="ContactUs"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidatorPhone" runat="server" ControlToValidate="Phone"
                ErrorMessage="Name is Required." ToolTip="Phone is required." Display="Static"
                Text="*" ValidationGroup="ContactUs">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <th style="text-align: right; padding-right: 3px;">
            Product
        </th>
        <td>
            <asp:TextBox ID="Product" runat="server" ValidationGroup="ContactUs"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidatorProduct" runat="server" ControlToValidate="Product"
                ErrorMessage="Name is Required." ToolTip="Product." Display="Static" Text="*"
                ValidationGroup="ContactUs">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <th style="text-align: right; padding-right: 3px;">
            Comment
        </th>
        <td>
            <asp:TextBox ID="Comment" runat="server" TextMode="MultiLine" ValidationGroup="ContactUs"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="Comment"
                ErrorMessage="Comment is Required." ToolTip="Leave comments or ask questions."
                Display="Static" Text="*" ValidationGroup="ContactUs">*</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td>
        </td>
        <td>
            <asp:Button ID="SendButton" runat="server" Text="Send" ValidationGroup="ContactUs"
                OnClick="SendButton_Click" />
        </td>
    </tr>
    <tr>
        <td>
        </td>
        <td>
            <asp:Label ID="MessageLabel" runat="server"></asp:Label>
            <asp:ValidationSummary ID="ContactUsSummary" runat="server" ValidationGroup="ContactUs" />
        </td>
    </tr>
</table>
Do you have the default email addresses set up in the Configure >> Email >> Settings page? That's where the "TO" email address comes from.
David
http://www.ecombuildertoday.com
Enhanced Reporting for AbleCommerce
Image

Richard47
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 47
Joined: Thu Nov 04, 2010 1:15 pm

Re: Contact us Conlib

Post by Richard47 » Wed Sep 26, 2012 10:49 am

Thanks David That seemed to work.

Richard

Post Reply