Im not so familiar with contactforms in Umbraco. I've seen a few packages like Cultivcontact and doc2form but i'm not actually looking for a formbuilder but the code to send the mail or <form> items.
The provider of my site uses the component: JMail.NET
Here is an example of the code:
Dim JMail As New Message Dim s As String = "emailaddress" Dim Address As Address = Address.Parse(s) Dim List As AddressList = New AddressList() List.Add(Address) 'List.Add(New Address("emailaddress")) for more addresses JMail.To = List JMail.From = "emailaddress" JMail.Subject = "subject" JMail.BodyText = "Text" JMail.Charset = Encoding.GetEncoding("iso-8859-1") Smtp.Send(JMail, "smtp.mijnhostingpartner.nl", 25, "mijnhostingpartner.nl", SmtpAuthentication.Login, "username", "password") JMail = Nothing
Before using umbraco i would simply create a SENDMAIL.ASP with this code and address to this page in a form submit. But what is the proper way in Umbraco.???
This sort of thing is a fairly standard way of sending emails in asp.net, is this what you mean?
publicstaticvoidSendMailMessage(stringfrom,string to,string bcc,string cc,string subject,string body) { // Instantiate a new instance of MailMessage MailMessage mMailMessage =newMailMessage();
// Set the sender address of the mail message mMailMessage.From=newMailAddress(from); // Set the recepient address of the mail message
mMailMessage.To.Add(newMailAddress(to));
// Check if the bcc value is null or an empty string if((bcc !=null)&&(bcc !=string.Empty)) { // Set the Bcc address of the mail message mMailMessage.Bcc.Add(newMailAddress(bcc)); }
// Check if the cc value is null or an empty value if((cc !=null)&&(cc !=string.Empty)) { // Set the CC address of the mail message mMailMessage.CC.Add(newMailAddress(cc)); }// Set the subject of the mail message mMailMessage.Subject= subject; // Set the body of the mail message mMailMessage.Body= body; // Set the format of the mail message body as HTML mMailMessage.IsBodyHtml=true; // Set the priority of the mail message to normal mMailMessage.Priority=MailPriority.Normal;
// Instantiate a new instance of SmtpClient SmtpClient mSmtpClient =newSmtpClient(); mSmtpClient.EnableSsl=true; // Send the mail message mSmtpClient.Send(mMailMessage); }
Description: An application error occurred on the
server. The current custom error settings for this application prevent
the details of the application error from being viewed remotely (for
security reasons). It could, however, be viewed by browsers running on
the local server machine.
Details: To enable the details of this specific error
message to be viewable on remote machines, please create a
<customErrors> tag within a "web.config" configuration file
located in the root directory of the current web application. This
<customErrors> tag should then have its "mode" attribute set to
"Off".
Notes: The current error page you are seeing can be
replaced by a custom error page by modifying the "defaultRedirect"
attribute of the application's <customErrors> configuration tag to
point to a custom error page URL.
I think that Umbraco is getting confused as you are posting back to an asp file, it is trying to process the asp file as a normal umbraco page. Try opening the web.config and finding this line
It's not possible to use classic asp pages in a standard Umbraco site, if you really need to do this you will need to change settings in IIS, and solve some session sharing issues that are not trivial to solve.
If you'd like to solve your problem using only the Umbraco backend (No Visual Studio Solution, precompiled dll's and stuff like that as shown in this video) You could implement a simple user control with this code, and upload it to the /usercontrols folder in your site calling it sendmail.ascx
After doing that you need to create a macro ponting to this usercontrol. Developers section -> Right Click "Macros" -> name "SendMail" Then select your usercontrol in the ".NET user controle" dropdown to the right and save your macro. Now you should be able to insert this macro in the templates (or in the Richtext editor if you checked "Use in editor" in the macro configuration)
Be aware that the code above relies on the SMTP server settings in your web.config file:
You need to set the host attribute value to an IP-addres or DNS server name of a SMTP server that will accept and forward Emails for your server. Your website or webserver hoster should be able to provide you with the necessary information there.
Although it's not possible to use classic ASP as Jesper correctly states you can call the asp page from umbraco as long as you exclude it from the Umbraco processing (by making that change to umbracoReservedUrls).
Your server 500 error is probably because there is a code issue with the ASP page, possibly you are not grabbing the post data from your form, try hardcoding some email values in the asp page to see if an email gets sent at all, if that works then ensure you are getting all the post information from the umbraco page.
Saying all that Jesper is correct, if possible I would set up something within Umbraco like he suggests, this would be the simplest solution!
Ofcourse i want to drop the 'old school' solutions and learn all about the Umbraco way.
I've been analyzing some contact forms like Cultvic en Koiak and starting to understand how things work. I got the both versions working now. Problem is that you need Visual Studio to make adjustments to the aspx.cv part which is responsible for the actual sending i believe. This information is compiled in the DLL's that come with these forms. Correct me if i'm wrong.
So i'm gonna try Jesper's suggestion bij writing a new aspx file with any limitation....
When i got things working i will post my solution for you.
And sorry for my late reply, I've been offline since Wednesday morning.
A little tip for you: When concatenating strings in .net it's much more efficient (as in using fewer cpu cycles) using a stringbuilder than concatenating with +=. It's probably negligable in this case, but hey good habits are invaluable right? Try:
using System.Text;
protected void SendMail(object sender, EventArgs e)
{
// Other code
var body = new StringBuilder();
body.AppendLine("Items sent from contact form:")
body.AppendLine();
body.AppendFormat("name : {0}", kname.Text);
body.AppendLine();
// More concatenations
umbraco.library.SendMail(kemail.Text, "my@address", "Contactform", body.ToString(), false);
// etc.
}
Glad you succeeded in getting you contact form working.
Sending mail from a contactform
Hi,
Im not so familiar with contactforms in Umbraco.
I've seen a few packages like Cultivcontact and doc2form but i'm not actually looking for a formbuilder but the code to send the mail or <form> items.
The provider of my site uses the component: JMail.NET
Here is an example of the code:
Dim JMail As New Message
Dim s As String = "emailaddress"
Dim Address As Address = Address.Parse(s)
Dim List As AddressList = New AddressList()
List.Add(Address)
'List.Add(New Address("emailaddress")) for more addresses
JMail.To = List
JMail.From = "emailaddress"
JMail.Subject = "subject"
JMail.BodyText = "Text"
JMail.Charset = Encoding.GetEncoding("iso-8859-1")
Smtp.Send(JMail, "smtp.mijnhostingpartner.nl", 25, "mijnhostingpartner.nl", SmtpAuthentication.Login, "username", "password")
JMail = Nothing
Before using umbraco i would simply create a SENDMAIL.ASP with this code and address to this page in a form submit.
But what is the proper way in Umbraco.???
Maarten
This sort of thing is a fairly standard way of sending emails in asp.net, is this what you mean?
Hi Steven,
This part i get.....
But i'v saved the vb script in 'sendmail.asp' and placed it in de root of the site.
In my page contact.aspx i have placed the following form:
Now when i press the submit-button i get an error
Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
I think that Umbraco is getting confused as you are posting back to an asp file, it is trying to process the asp file as a normal umbraco page. Try opening the web.config and finding this line
<add key="umbracoReservedUrls" value="~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx" />
If you change this to:
<add key="umbracoReservedUrls" value="~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,sendmail.asp" />
This will make umbraco ignore the page so it should hopefully then just work.
Hi Steven,
i altered the web.config added as you suggested, but still getting an error although it is a different error.
Now receiving the following error:
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
Maarten
Hi Maarten,
It's not possible to use classic asp pages in a standard Umbraco site, if you really need to do this you will need to change settings in IIS, and solve some session sharing issues that are not trivial to solve.
If you'd like to solve your problem using only the Umbraco backend (No Visual Studio Solution, precompiled dll's and stuff like that as shown in this video) You could implement a simple user control with this code, and upload it to the /usercontrols folder in your site calling it sendmail.ascx
After doing that you need to create a macro ponting to this usercontrol.
Developers section -> Right Click "Macros" -> name "SendMail"
Then select your usercontrol in the ".NET user controle" dropdown to the right and save your macro. Now you should be able to insert this macro in the templates (or in the Richtext editor if you checked "Use in editor" in the macro configuration)
Be aware that the code above relies on the SMTP server settings in your web.config file:
You need to set the host attribute value to an IP-addres or DNS server name of a SMTP server that will accept and forward Emails for your server. Your website or webserver hoster should be able to provide you with the necessary information there.
Regards
Jesper Hauge
Although it's not possible to use classic ASP as Jesper correctly states you can call the asp page from umbraco as long as you exclude it from the Umbraco processing (by making that change to umbracoReservedUrls).
Your server 500 error is probably because there is a code issue with the ASP page, possibly you are not grabbing the post data from your form, try hardcoding some email values in the asp page to see if an email gets sent at all, if that works then ensure you are getting all the post information from the umbraco page.
Saying all that Jesper is correct, if possible I would set up something within Umbraco like he suggests, this would be the simplest solution!
Thanks guy's for all the help and suggestions...
Ofcourse i want to drop the 'old school' solutions and learn all about the Umbraco way.
I've been analyzing some contact forms like Cultvic en Koiak and starting to understand how things work. I got the both versions working now. Problem is that you need Visual Studio to make adjustments to the aspx.cv part which is responsible for the actual sending i believe. This information is compiled in the DLL's that come with these forms. Correct me if i'm wrong.
So i'm gonna try Jesper's suggestion bij writing a new aspx file with any limitation....
When i got things working i will post my solution for you.
Maarten
Hi Jesper,
Your script is working perfect..
So i promised to keep you posted once i altered the script.
My new script is not working. I'm not receiving any mails. But also receive no errors. Here is the code:
Any idea ?
Maarten
Thanks Jesper...
I got it solved
Maarten
Hi Maarten,
And sorry for my late reply, I've been offline since Wednesday morning.
A little tip for you: When concatenating strings in .net it's much more efficient (as in using fewer cpu cycles) using a stringbuilder than concatenating with +=. It's probably negligable in this case, but hey good habits are invaluable right? Try:
Glad you succeeded in getting you contact form working.
Regards
Jesper Hauge
Thanks Jesper,
I changed the script according your adjustments...
One small question.. for some reason i'm unable to send the mail to more then 1 recipient. Something like this:
Both recipients have the same domain mailaccounts; [email protected] and [email protected]
For some reason only the last recipient receives the mail.
Any Idea?
And last...i would like the recipient(s) to be variables that can be inserted with the macro. I've never done this before.
Maarten
Hi Maarten,
Inside the framework umbraco.library.SendMail calls new MailMessage(string, string) which accepts multiple adresses, separated by commas try sending a string looking like this: "[email protected],[email protected]", and it should be okay.
Regarding getting variables from the macro into the usercontrol I think you can do it using macro parameters and a public property on the usercontrol.
There's a guide on how to do that in this PDF: http://umbraco.com/media/42a0202c-b0ba-4f84-bcf1-64dfd5230322-usingcontrolswithumbraco.pdf
Regards
Jesper Hauge
Hi Jesper, Thanks for all your help.
I got everything working now and learned a few things.
kind regards,
Maarten Boer
is working on a reply...