Use MIME::Lite to create a multipart message with attachment

MIME::Lite is a great Perl module for working with MIME formatted email messages. However, one problem I ran into was trying to create a multipart message that has 1) a text version of the message 2) an HTML version of the message and 3) an HTML attachment. If I set the content type to “multipart/alternative” then the attachment showed up as part of the message but if I set the content type to “multipart/mixed” then the message showed up as an attachment. I couldn’t find a solution online so I figured it out on my own. Hopefully this helps someone in the future.

To get things right you have to create a multipart/alternative message that is nested within a multipart/mixed message. Here is the code I used:

my $html = “<html><body>This is the HTML message</body></html>”;
my $text = “This is the text message”;
my $attachment = “<html><body>This is the HTML attachment</body></html>”;
my $email = “someone@example.com”;

my $msg = MIME::Lite->new(
From        =>  ‘me@example.com’,
To          =>  $email,
Subject     =>  ‘Test message’,
Type        =>  ‘multipart/mixed’
);

my $part = MIME::Lite->new(
Type => ‘multipart/alternative’,
);
$part->attach(
Type => ‘text/html; charset=utf-8′,
Data => $html,
);
$part->attach(
Type => ‘text/plain’,
Data => $text,
);
$msg->attach($part);

$msg->attach(
Type => ‘text/html’,
Data => $attachment,
Filename => ‘filename.htm’,
Disposition => ‘attachment’
);

$msg->send;
if ( $msg->last_send_successful() ) {
print “  Message sent to $email\n”;
} else {
print “  Error sending email to $email\n”;
}

Cisco ASA Command Line

If you work with Cisco devices on an infrequent basis, use this handy cheat sheet to navigate through the CLI.

Command Description
show ip route Displays entire routing table
show ip interfaces brief Displays a summary of all interfaces
show running-config Displays the running config
copy run tftp Copies running-config to a TFTP server
write net Same as above for PIX 501
copy tftp run Copies configuration file from TFTP server to DRAM
config net Same as above for PIX 501 (must be in global config mode first)
copy run start Copies running-config to startup-config
write mem Same as copy run start
reload Causes the router to reboot and reload from startup-config
erase start Deletes the startup-config. (Factory Reset)
write erase Same as above for PIX 501
show version Displays software version
enable Moves from user mode to privileged mode
config term Moves from privileged mode to global configuration mode
exit Moves back one level
ip domain name Sets the domain name
crypto key generate rsa Creates RSA hash for SSH
ca gen rsa key 1024 Same as above (PIX 501)
ca save all Saves the newly generated key to flash (PIX 501)
show crypto isakmp sa Displays Phase 1 info
show crypto ipsec sa Displays Phase 2 info
clear crypto isakmp sa Deletes any active isakmp security associations
clear crypto ipsec sa Deletes any active ipsec security associations
more system:running-config Shows the running config without masking pre-shared keys
show xlate Shows information about NAT translations
show local Shows number of local hosts vs. licensed hosts
show activation-key Shows the currently activated features
activation-key xxxx Installs a new activation key

Configuring a VMWare Cluster with 2 hosts and a Dell MD3220i storage array

I recently had the chance to setup a brand new SAN with two Dell R420 servers, two Dell PowerConnect switches, and a Dell MD3220i storage array with dual controllers. The goal was to install VMWare ESX 5.1 on the servers and attach them both to the storage array using iSCSI. We wanted to set them up in a cluster with shared storage so that if one server went down, the VM’s would be bootable on the other server (i.e. High Availability).

I found a tremendously helpful article by Bruce9404 but I wanted to document my steps here in case I ever have to do this again.

The Dell MD3220i has two controllers with four ports each. In addition, each controller also has a management port for configuring the array.

MD3200i_rear

 The four iSCSI ports should be connected to your SAN, while the management port should be connected to your corporate LAN. To configure the array, you need to download and install the Dell Modular Disk Storage Manager (MDSM) software. Install the software on any PC in your LAN and it will automatically discover the storage array and both controllers. Simply right-click the storage array and select “Manage Storage Array”

Now we need to configure the iSCSI ports on both controllers. Since there are four ports on each controller, we are going to need four different subnets. I chose:

Subnet 0: 192.168.200.0/24
Subnet 1: 192.168.201.0/24
Subnet 2: 192.168.202.0/24
Subnet 3: 192.168.203.0/24

It doesn’t really matter what subnets you choose as long as they are unique and not the same as your LAN subnet.

I labeled the subnets 0-3 so they would match up with the iSCSI ports. So iSCSI port 0 will need a IP address on subnet 0, iSCSI port 1 will need an IP on subnet 1, and so on. Here is what I came up with:

iSCSI port Controller 0 Controller 1
0 192.168.200.101 192.168.200.102
1 192.168.201.101 192.168.201.102
2 192.168.202.101 192.168.202.102
3 192.168.203.101 192.168.203.102

Click on the Setup tab and go to “Configure iSCSI host ports” to configure these IP addresses. Note that since our SAN is not connected to any other networks, there is no need for a default gateway. You can leave that field blank.

iSCSI configuration

Now we could connect all of these ports to a single switch but for redundancy sake, we have two switches. Lets assign subnet 0 and 1 to the first switch, and subnet 2 and 3 to the second switch. I like to use different colored patch cables for each switch. Here is what my setup looks like:

SAN wiring diagram

POP3 Connector chokes on messages with invalid header

Problem

If you are using the POP3 Connector on Windows SBS 2008, you may encounter this error in the event log

One or more (5) e-mail messages in the POP3 mailbox account ‘<email address>’ on the POP3 server ‘<server name>’ have invalid header fields. Because of this, the messages cannot be delivered to the Exchange Server mailbox ‘<mailbox>’ in Windows Small Business Server. The messages are still on the POP3 server. To resolve this issue, connect to the POP3 mailbox account, and then manually retrieve or delete the messages.

By default the POP3 connector will stop processing new messages after 5 protocol errors so once this happens, you will not receive any email.

Solution

The quickest and easiest thing to do is to increase the MaxProtocolErrors from 5 to something bigger like 999. You can do this with the following command:

Set-ReceiveConnector -identity ($Env:computername + “\Windows SBS Fax Sharepoint Receive ” + $Env:computername) -MaxProtocolErrors 999

This will allow the remaining messages to be downloaded, but the messages with invalid headers will still not be downloaded. Once you accumulate 999 messages with invalid headers, the problem will still occur.

To fix this you either have to login to your ISP’s mail server and delete the messages manually or figure out why the messages have bad headers. In my case, the problem was that the messages had an invalid Return-Path: header that looked like this:

Return-Path: <MAILER-DAEMON>

I noticed that most of the messages were automated responses such as “out-of-office” replies. The problem is the MAILER-DAEMON is not a valid email address format. Valid email addresses must have an @ sign in them. The workaround I found was to tell Exchange to append the local domain name. Here is the command for that:

Set-ReceiveConnector -Identity ($Env:computername + “\Windows SBS Fax Sharepoint Receive ” + $Env:computername) -DefaultDomain $Env:UserDNSDomain

Once I did that, the POP3 connector was able to download the messages with invalid headers and the errors in the event log went away.

Other resources:

http://www.tech-archive.net/Archive/Windows/microsoft.public.windows.server.sbs/2009-03/msg00163.html

http://www.tech-archive.net/Archive/Windows/microsoft.public.windows.server.sbs/2011-09/msg00014.html

 

 

Journal Wrap Error causing file replication to fail

Problem

Active Directory replication between domain controllers is not working and Event 13568 is logged in the File Replication log with the following message

The File Replication Service has detected that the replica set “DOMAIN SYSTEM VOLUME (SYSVOL SHARE)” is in JRNL_WRAP_ERROR.

Solution

The description for Event 13568 is very helpful. It’s one of the few error events that actually tells you how to fix the problem in the error description. If you have a single Domain Controller, these steps are very straightforward. However, if you have multiple domain controllers you need to determine which domain controller has the most up-to-date replica. These instructions assume that the server with the journal wrap error is also the server with the most up-to-date replica of your SYSVOL share.

Step 1:

Open the registry editor and navigate to:

HKLM\System\CurrentControlSet\Services\NtFrs\Parameters

You will find a REG_DWORD key called “Enable Journal Wrap Automatic Restore”. Change the value of this key to 1.

If the value name is not present you may add it with the New->DWORD Value function under the Edit Menu item. Type the value name exactly as shown above.

Step 2:

Restart the File Replication Service. You can do this through the Services Control Panel or by typing these commands:

net stop ntfrs
net start ntfrs

Now you must wait 5 minutes. After 5 minutes have gone by, you should check the File Replication Service event log for event 13516 indicating that “The File Replication Service is no longer preventing the computer SERVERNAME from becoming a domain controller”. If you see this event, everything is good and you can skip to step 3

In some cases you may see event id 13520 which says “The File Replication Service moved the preexisting files in c:\windows\sysvol\domain to c:\windows\sysvol\domain\NtFrs_PreExisting___See_EventLog.”

Set Burflags to D4

Move files from c:\windows\sysvol\domain\NtFrs_PreExisting___See_EventLog back to c:\windows\sysvol\domain

Restart the ntfrs service

Wait for event 13516

Check to make sure the sysvol folder is shared

Step 3:

Go back into the Registry Editor and change the “Enable Journal Wrap Automatic Restore” back to 0

 

How to exclude your own traffic in Google Analytics

So you’ve got Google Analytics set up and you’re tracking your web site statistics. But every time you visit your web site (to do testing, training, etc.) your reports are skewed because they include traffic from your own computer. One way to fix this is to set a cookie on your computer with some predetermined value, and then use a filter in Google Analytics to exclude traffic from any computer that has that cookie set.

Step 1: Create a page to set a cookie

Create a new html page on your website that contains the following code:

<html>
<head>
INSERT YOUR TRACKING CODE HERE
</head>
<body onLoad=”javascript:_gaq.push(['_setVar', 'test_value']);”>
<p>Your traffic from this browser will now be excluded from Google Analytics</p>
</body>
</html>

Make sure you insert your Google tracking code between the <head></head> tags. Save the file as “exclude_traffic.htm” in the root of your website.

Step 2: Visit the page with your browser

Open up your browser and navigate to the page you just created. For example:

http://www.yourdomain.com/exclude_traffic.htm

You should see a page that says “Your traffic from this browser will now be excluded from Google Analytics”. If you use multiple browsers to test your web site, you will need to visit the page from every browser you use.

Step 3: Create a filter

Login to your Google Analytics account and create a new filter (click “Admin” then go to the Filters tab). Create a custom filter with the following attributes:

Filter Type: Custom filter – Exclude
Filter Field: User Defined
Filter Pattern: test_value

Finally, make sure you apply the filter to all your profiles.

 

 

 

Postini service end of life

Google announced last month that it’s shutting down it’s popular Postini email filtering service and forcing users to transition to Google Apps. Google will stop selling Postini services on December 31, 2012 and completely shut the service down by the end of 2013. Users that don’t want to switch to Google Apps will have few options. Google’s website tells users “your Postini service will terminate at your contract end date” unless they switch to Google Apps. It’s even worse for users of Google Message Filtering, Postini Small Business Edition, and Postini Service Provider Edition. Those services will not be migrated to Google Apps and users will receive a non-renewal notice.

So what are Postini’s 26 million users going to do? One option is to switch to a service like MX Guardian. MX Guardian is ideal for small to medium-sized businesses that want secure, reliable spam and virus filtering for their entire domain. There is no need to setup users in advance. Just a simple change to the domain’s MX record and everyone is happy. Spam and virus-infected messages are blocked and quarantined before they enter the customers network. An administrator can view and release messages from the quarantine through a user-friendly web interface.

For more information, visit: http://www.mxguardian.net

Full disclosure: MX Guardian is owned by Kent Oyer

Some users and groups do not show up in the SBS Console

Problem

If you do not create users and groups using the SBS Console, they will not show up in the SBS Console. If you create users and groups through another method, you can use this procedure to modify the users and groups so they show up in the SBS Console.

Solution

For Users:

  1. Open the SBS Console
  2. Go to the Users tab under Users and Groups
  3. Click Change user role for user accounts
  4. Select the role you want to assign to the user
  5. Select Add user permissions or settings and click Next
  6. Check Display all user accounts in the Active Directory
  7. Select the user(s) you want to change and click Change User Role

For Groups

Windows SBS 2008

  1. Download the Windows Small Business 2008 Active Directory Group Converter

http://www.microsoft.com/en-us/download/details.aspx?id=21670

Windows SBS 2011

  1. Under c:\Program Files\Windows Small Business Server\bin, double-click GroupConverter.exe to launch the Active Directory Group Converter

Mac printing to a non-Postscript printer

I have to admit I am not a Mac expert. I am a PC guy but I have learned a few things about Mac’s over the years. One of which is that Mac’s like to use Postscript as the default emulation method for printing. Unfortunately, not all printers support Postscript out of the box. In my case, the customer had a Sharp MX-2600N color printer that did not have the Postscript Expansion Kit installed. So even though I downloaded the Mac driver directly from Sharp, the printer would just display a generic error message whenever I sent it a test page.

Fortunately, I found something called Foomatic-RIP. You need to install Foomatic-RIP as well as Ghostscript. Both packages can be downloaded from here:

http://www.linuxfoundation.org/collaborate/workgroups/openprinting/macosxfoomatic

Once those two things are installed, then you just need a printer definition file (PPD) for your particular printer. You have several choices:

1. You can download and install pxlmono, which is a package of over 1,000 different PPD’s for various printers. If you’re lucky enough to have a printer on this list, you can get pxlmono from here:

http://www.linuxfoundation.org/collaborate/workgroups/openprinting/macosxpxlmono

2. You can create your own PPD. Since PPD’s are just text files, you might be able to take a PPD for a similar printer and modify it to suit your needs. I’m sure there is a good tutorial for this somewhere on the net, but if that seems like too much work there’s always option 3…

3. Do a Google search for your printer model and “PPD”. Hopefully somebody out there with your exact same printer has already done the work for you. That’s what I did and I found the exact PPD file I needed.

PPD files usually have a .ppd.gz extension because they are gzip’ed. You do NOT need to unzip them. Simply put the gzip’ed ppd file in your /Library/Printers/PPDs/Content/Resources/ folder. You will know you are in the right place if you see a bunch of other PPD files in the same folder.

The final step is to just add a new printer like you would normally on a Mac. If you put the PPD in the right place, it should show up as an option on the “Print Using” dropdown menu.

 

 

 

Out of Office Assistant not working in Outlook 2007 with Exchange 2007

If you are running Outlook 2007 with Exchange 2007 (or Small Business Server 2008) you may experience problems with the Out of Office Assistant. The error message you may receive is:

Your Out of Office settings cannot be displayed, because the server is currently unavailable. Try again later.

In addition, if you open the Exchange Management Shell and run

Test-OutlookWebServices | fl

You will receive this error message when it tries to test the Autodiscover service:

WARNING: An unexpected error has occurred and debug information is being
generated: Object reference not set to an instance of an object.
Test-OutlookWebServices : Object reference not set to an instance of an object.

This indicates a problem with the Autodiscover service. The Out of Office assistant is dependent on the Autodiscover service to work properly.

This can happen if you have the .NET Framework 3.5 SP1 installed on your Exchange server (or more specifically, your Exchange Client Access Server). The problem is not actually with the .NET Framework 3.5 however. The problem is with the .NET Framework 2.0 SP2 which gets installed automatically when you install .NET 3.5.

Microsoft has a hotfix for this issue, which is also included in Server 2008 SP2. However, in my case the hotfix didn’t resolve the issue. The solution for me was to uninstall .NET Framework 2.0 SP2. This is easy to do if you know where to find it. Here’s a step-by-step guide

  1. Open Control Panel
  2. Go into Programs and Features
  3. In the sidebar, click “View Installed Updates”
  4. Scroll down until you find “Update for Microsoft Windows (KB948609)”
  5. Highlight it and click “Uninstall”

Then try to open the Out of Office Assistant again.

Just as a final note, you should also make sure you have a DNS record for autodiscover.youdomain.com that points to your Exchange server. So if your email address is joe@somedomain.com then you should have a DNS record that points autodiscover.somedomain.com to the IP address of your Exchange server. If your server is behind a NAT router, you should create a DNS record on your external DNS server that points to your server’s external IP address, and you should create a DNS record on your internal DNS server that points to your server’s internal IP address. If your internal and external domain names are different, you may need to review this article.

I hope that helps!