Tag Archives: smtp

Testing SMTP, POP3 and IMAP protocol access

This article assumes you have access to telnet and openssl. The example tests have been run against a Microsoft Exchange 2010 server. The IP and hostname have been obfuscated. The commands needed to perform these protocol access tests will be the same on both Linux and Windows.

Testing SMTP

Test using plain text

Execute the following command to initiate a plain text connection over port 25.

telnet smtp.server.com 25

Example output

The following is the typical output you’ll see as a response from a SMTP server. In this case being Microsoft Exchange 2010.

Trying 74.161.5.111...
Connected to smtp.server.com.
Escape character is '^]'.
220 smtp.server.com Microsoft ESMTP MAIL Service ready at Thu, 3 May 2012 13:06:21 +0200

Test using an encrypted connection

Execute the following command to initiate an encrypted connection over port 25.

openssl s_client -starttls smtp -crlf -connect smtp.server.com:25

Parameters

Beneath you’ll see the documentation for the parameters used in the above example.

-starttls protocol
send the protocol-specific message(s) to switch to TLS for communication.  protocol is a keyword for the intended protocol.  Currently, the only supported keywords are "smtp", "pop3", "imap", and "ftp".
-crlf
this option translated a line feed from the terminal into CR+LF as required by some servers.

Example output

There’s little to see here mainly because I had to exclude the certificate verification information to anonymize the test server.

<certificate verification output>
250 CHUNKING

Tip: You may run the usual SMTP commands directly from the command prompt after you initiated the encrypted connection.

Testing IMAP

Test using plain text

Execute the following command to initiate a plain text connection over the standard IMAP port 143.

telnet imap.server.com 143

Example output

The following is the typical output you’ll see as a response from an IMAP server. In this case being Microsoft Exchange 2010.

Trying 74.161.5.111...
Connected to imap.server.com.
Escape character is '^]'.
* OK The Microsoft Exchange IMAP4 service is ready.

Test using an encrypted connection

openssl s_client -connect imap.server.com:993

Example output

<certificate verification output>
* OK The Microsoft Exchange IMAP4 service is ready.

Testing POP3

Test using plain text

telnet pop.server.com 110

Example output

The following is the typical output you’ll see as a response from a POP server. In this case being Microsoft Exchange 2010.

Trying 74.161.5.111...
Connected to pop.server.com.
Escape character is '^]'.
+OK The Microsoft Exchange POP3 service is ready.

Test using an encrypted connection

openssl s_client -connect pop.server.com:995

Example output

<certificate verification output>
+OK The Microsoft Exchange POP3 service is ready.

References

SMTP – Simple Mail Transfer Protocol
IMAP – INTERNET MESSAGE ACCESS PROTOCOL
POP 3 – Post Office Protocol – Version 3
The OpenSSL Project

// CrashMAG

Windows Server Backup Notifications

This will describe what you will need to do to get your Windows Server to email you alerts when Windows Server Backup either succeeds or fails.

The article contains 2 sections, one for creating a task to notify you on failures. And one for notifying you on success. It does require access to an SMTP server.

Notify on failure

  1. Open Task Scheduler
  2. Create a task
  3. Tick the “Run whether the used is logged on or not” option
  4. Go to the trigger tab, press “New”, choose “On an event”, select “Custom” and then “New Event Filter”
  5. Select “By log”, then navigate to “Applications and services logs”, then “Microsoft, then “Windows” then find “WindowsBackup” and tick it
  6. Use the following Event ID’s
    5,8,9,17-22,49,50,52,100,517,518,521,527,528,544,545,546,561,564,612
  7. Save your changes and navigate to the actions tab of the task
  8. Press “New” and select “Action: Send an email”. Fill out the details to you liking and save

If you want to test your email notifications, be sure to check the “Allow task to be run on demand” option under the Settings tab.

Notify on success

  1. Open Task Scheduler
  2. Create a task
  3. Tick the “Run whether the used is logged on or not” option
  4. Go to the trigger tab, press “New”, choose “On an event”, select “Custom” and then “New Event Filter”
  5. Select “By log”, then navigate to “Applications and services logs”, then “Microsoft, then “Windows” then find “WindowsBackup” and tick it
  6. Use the following Event ID’s
    4
  7. Save your changes and navigate to the actions tab of the task
  8. Press “New” and select “Action: Send an email”. Fill out the details to you liking and save

If you want to test your email notifications, be sure to check the “Allow task to be run on demand” option under the Settings tab.

Refrence

TechNet listing of Event ID’s

// CrashMAG

Windows Server Backup Powershell Script

This is a small Powershell script that will use the command line version of Windows Server Backup (wbadmin). It has the ability to email you upon failure or success. It will also include the log as an attachment to the script.

The variables that needs to be edited should be obvious.

I’ve found parts of this script while googling, but I’ve added a small logic that will create the backup location if it does not exist already.

#—————————————–Start script—————————————————-

function SendEmail($To, $From, $Subject, $Body, $attachment, $smtpServer) 
{ 
        Send-MailMessage -To $To -Subject $Subject -From $From -Body $Body -Attachment $attachment -SmtpServer $smtpServer 
} 
$emailto=”email@address.com” 
$emailfrom=”email@address.com” 
$day=(get-date -f dd-MM-yyyy)
$hname="HOSTNAME"
$backuplocation="\\BACKUP-SERVER\SHARE\$hname\$day\" 
$backuplog="$backuplocation"+(get-date -f dd-MM-yyyy)+"-backup-$hname.log" 
$emailserver="EMAIL-SERVER" 

function Out-FileForce {
PARAM($backuplocation)
PROCESS
{
    if(Test-Path $backuplocation)
    {
        Out-File -inputObject $_ -append -filepath $backuplocation
    }
    else
    {
        new-item -force -path $backuplocation -value $_ -type file
    }
}
}

Write-Output ("———————– Backup started on – $(Get-Date –f o) ————————-") | Out-FileForce "$backuplog" 
$Error.Clear() 
wbadmin start backup -backupTarget:$backuplocation -include:c: -systemstate -allcritical -vsscopy -quiet | Out-FileForce "$backuplog" 
if(!$?) 
    { 
        Write-Output ("———————– An error has occurred! Check it please!. – $(Get-Date –f o) ————————-") | Out-File "$backuplog" -Append 
        SendEmail -To "$emailto" -From "$emailfrom" -Subject "backup failed" -Body "The backup has failed! Please check attached log." -attachment "$backuplog" -smtpServer "$emailserver" 
        break 
        
    }

Write-Output ("———————– Everything is OK! – $(Get-Date –f o) ————————-") | Out-File "$backuplog" -Append 
SendEmail -To "$emailto" -From "$emailfrom" -Subject "backup $hname ok" -Body "The backup has succeeded!" -attachment "$backuplog" -smtpServer "$emailserver" .

#——————————————–End script——————————————————

// CrashMAG