MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

Contact form has an issue with mail server security  (Mono Support )

Viewed 9227 time(s), 7 post(s) 4/10/2014 8:21:48 AMby panos.pag
panos-pag

panos.pag

4/10/2014 8:21:48 AM
Hello,

the Contact form has an issue with mail server security.

(MonoX v4.7.40.3597 [6/12/2012], DB v4.5.3103)

It tries to send an e-mail to the site's team with "From" field being the address of the person who gives feedback which is not allowed by the mail server.

How can it be changed to have for "From" our own address and put the poster's e-mail into the body of the message intead or have it at the text of the from field? e.g.
"On behalf of xx@yy.com" <ourmail@ourserver.com>
This content has not been rated yet. 
390 Reputation 35 Total posts
idrazic

idrazic

4/10/2014 9:17:09 AM
Hi Panos

You can implement this by adding a BeforeSendMail event handler to the ContactFormModule.

Regards,
Igor
This content has not been rated yet. 
1384 Reputation 152 Total posts
panos-pag

panos.pag

4/10/2014 9:59:14 AM
Thank for your reply!

Can we put the event handler by hand or do we need to use Visual Studio for that? do we need to create a separate ContactFormModule.ascx.cs file?

Thanks! 
Panos
This content has not been rated yet. 
390 Reputation 35 Total posts
idrazic

idrazic

4/10/2014 1:17:46 PM
You don't need ContactFormModule.ascx.cs, just add a separate Page Contact.aspx with the same markup and add "ctlContact.BeforeSendMail +=" there. You would need to change the footer link too though.

If you have the source code edition, fastest is to just add code like this to Contact.aspx.cs
protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    ctlContact.BeforeSendMail += new ContactForm.BeforeSendMailEventHandler(ctlContact_BeforeSendMail);
}
 
void ctlContact_BeforeSendMail(System.Net.Mail.MailMessage mailMessage, System.ComponentModel.CancelEventArgs e)
{
    // Your code here
}

This content has not been rated yet. 
1384 Reputation 152 Total posts
Zoomicon

Zoomicon

4/10/2014 4:23:02 PM
thanks for the guidance, it came to me that I don't need a separate webpage if I used embedded C# script in the page and make use of AutoEventWireup functionality of ASP.net

only issue I see with the embedded script below is that it ignores the \n\n I add and sees it as a space char (wonder if the reason is that the body contains html mail instead of plain text. Should I use <br /><br /> instead? I hope you provide an autogenerated text flavour of the html e-mail for clients that have html disabled, although for the contact form we don't care much since the mail is sent to us)

<%@ Page
    Language="C#"
    AutoEventWireup="True"
    CodeBehind="Contact.aspx.cs"
    Inherits="MonoSoftware.MonoX.Pages.Contact"
    Theme="Default"
    MasterPageFile="/MonoX/MasterPages/DefaultSmallHeader.master"
%>
        
<%@ MasterType TypeName="MonoSoftware.MonoX.BaseMasterPage" %>   

<%@ Import Namespace="MonoSoftware.MonoX.Resources" %>
<%@ Register TagPrefix="MonoX" TagName="Editor" Src="/MonoX/ModuleGallery/MonoXHtmlEditor.ascx" %>
<%@ Register TagPrefix="MonoX" TagName="ContactForm" Src="/MonoX/ModuleGallery/ContactFormModule.ascx" %>
<%@ Register Assembly="MonoX" Namespace="MonoSoftware.MonoX" TagPrefix="portal" %>

<script language="C#" runat="server">
  private void ContactForm_BeforeSendMail(System.Net.Mail.MailMessage mailMessage, System.ComponentModel.CancelEventArgs e)
  {
    mailMessage.Body = "from: " + mailMessage.From + "\n\n" + mailMessage.Body;
    mailMessage.From = new System.Net.Mail.MailAddress("clipflair@cti.gr");
  }
</script>


<asp:Content ID="Content1" ContentPlaceHolderID="cp" runat="server">             
    <portal:PortalWebPartZoneTableless HeaderText='<%$ Code: PageResources.Zone_ContentZone %>' ID="contentPartZone" runat="server" Width="100%" ChromeTemplateFile="Standard.htm">
        <ZoneTemplate>
            <MonoX:ContactForm ID="ctlContact" runat="server"
            A_WebSiteName="ClipFlair" A_Address="..." A_City="..."
   A_ZipCode="..." A_Country="..." A_Phone="...." A_Fax="...."  EnableSSL="false" A_EMail="..."
            OnBeforeSendMail="ContactForm_BeforeSendMail"
   />
        </ZoneTemplate>
    </portal:PortalWebPartZoneTableless>
</asp:Content>

This pattern can be used in other cases one wants to extend/alter MonoX functionality and they use the precompiled version
Rated 5.00, 1 vote(s). 
2793 Reputation 345 Total posts
idrazic

idrazic

4/11/2014 8:22:17 AM
It's not our practice to use embedded c# in the markup, that's why I was avoiding such solution.
Furthermore this makes MonoX upgrade difficult as you would need to manually edit back your changes.

The contact form sends an email in html only (you can change that with IsBodyHtml and add AlternateView).
I think contact form is the sole example where the alternate view is not created (for the reason you mentioned yourself). Every e-mail sent to users has both views.

Regards,
Igor
This content has not been rated yet. 
1384 Reputation 152 Total posts
Zoomicon

Zoomicon

4/11/2014 9:27:44 AM
we have changes in the contact page anyway so that way we only have to merge changes in one file
I tend to prefer codebehind myself too
This content has not been rated yet. 
2793 Reputation 345 Total posts