Sitecore’s “Send Email Message” save action retains mail server settings

Today I faced an issue with Web Forms for Marketers (WFFM). We had taken a copy of a customer’s system and were trying to test some changes we’d made to it. This involved making sure that the system sent email correctly, and we wanted it to send them to a mail-trap, rather than sending them to actual users. However, when I tried to change the mail server settings, the forms of the system seemed to continue to try to use the customer’s live SMTP server. This was surprising. Continue reading “Sitecore’s “Send Email Message” save action retains mail server settings”

Sitecore’s “Send Email Message” save action retains mail server settings

Enable SSL for sending emails on Sitecore

I was asked to use a GMail server to send emails from Sitecore with. This is actually a pretty reasonable request – but GMail only supports connections over TLS or SSL. Configuring Web Forms for Marketers to use this was proving … interesting, until I found this excellent article by Mark CassidyContinue reading “Enable SSL for sending emails on Sitecore”

Enable SSL for sending emails on Sitecore

Sending Email from Azure with SendGrid

In SharePoint Online I need to send email(s) when a user updates a document. Who this email goes to involves some fairly complex logic – which we’ll ignore for this post. So how do we send the email? SharePoint Online doesn’t allow you to use SPUtility.SendEmail() or System.Net.Mail.SmtpClient – so unless you’re using standard alerts, or the workflow “Send Email” activity, well, you’re going to have to look elsewhere. I didn’t think SharePoint designer Workflows were quite up to the complexity of it, so I started to look elsewhere – at Remote Event Receivers, provider-hosted in Azure.

This leads to the question “can Azure send email?” I can imagine a few reasons why it maybe shouldn’t (think “spam”). Continue reading “Sending Email from Azure with SendGrid”

Sending Email from Azure with SendGrid

HTML 5 – Email Address Validation Regex

And interesting one to stumble upon – the ‘official‘ regex for validating a email address:

Edit: I’ve had to break this down into parts – for some reason WordPress throws a 403 error if I don’t. I think it sees this regex as a security risk!

Before the @ sign:
^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+

The @ sign and after:
@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)*$

Reads like it should work pretty well to me. I didn’t realise before the @ was so generous. And you could shrink it by using a case insensitive operator.

HTML 5 – Email Address Validation Regex

C# Code to send an email

I’ve been doing some testing of email enabled lists, and I needed to send quite a lot of emails, so I wrote a little console app to do it. Here’s the core of the code I used, in case I need it again, or it’s useful to someone. It uses System.Net.Mail:

SmtpClient smtp = new SmtpClient(@"vm-moss2007.virtual.local");
for (int i = 1; i <= 100; i++)
{
    MailMessage message = new MailMessage("administrator@virtual.local", <a href="mailto:testlist@sharepoint.virtual.local">testlist@sharepoint.virtual.local</a>);
    message.Subject = string.Format("Message {0}", i);
    message.Body = string.Format("This is message '{0}'", i);
    Console.WriteLine("Sending {0}", i);
    smtp.Send(message);
}
C# Code to send an email

Programmatically figure out the Email address of a list

I like mail enabled lists – they’re not perfect, but they are nice, and most folks can handle working email.

Sometimes, though, you want to programmatically create and enable these lists. That’s cool – but how do you figure out the email address of the list afterward?

You can get the first part of the address from the SPList object’s EmailAlias property. But that’s only the bit before the ‘@’ sign – what about the end of the address? Well, you get that from the farm:

emailAlias = list.EmailAlias + "@" + SPFarm.Local.Services.GetValue<SPIncomingEmailService>("").ServerDisplayAddress;

This gets the rest of the address (in my case ‘sharepoint.virtual.local’). Job done.

Programmatically figure out the Email address of a list