Mailhop Relay- Prevent Incoming Emails from Bouncing…

June 18th, 2010

Email is a fundamental part of communciatons today and has been around since the early days when the Internet was more commonly referred to as ARPANET.   The majority of Internet users have more than one email address; a hotmail account, gmail account, work email and a yahoo email account.  Businesses also rely upon email and if email servers are down or email is lost then that could cost a business dearly.

Mailhop Relay

Have you ever sent an email to an address and recieved a reply similar to “Message Undeliverable: “, this could be down to several issues such as the recipients email address not being found or the recipients mail server being down.   Now if someone is sending you an email and they receive a similar email, then that could mean that you Mail Server is down.  When your emails are bouncing like this, emails can be lost and more importantly business can be lost.

In order to prevent incoming mail from being lost you can use a thing called a mailhop relay. A mail hop can prevent mail from being lost when your email server is down and can also stop emails being bounced back to the email sender.

How a Mailhop Relay works.

Mailhop relay works by using MX records (Mail Exchange records) and each MX record has a priority and is linked to a specific mail server.  You can set up your mail server as the primary mail server then the mailhop relay server as the secondary server.  If the first server fails then the second server will hold on to the mail and attempt to redeliver the emails to you.  For instance your MX records could be set up as so:

mydomain.com MX preference = 10, mail exchanger = mail.mydomain.com
mydomain.com MX preference = 20, mail exchanger = mx2.mailhop.org

If mail.mydomain.com goes down then mx2.mailhop.org can take over.

Php strpos find in string function

June 10th, 2010

strpos($theString,$theValue)

If you want to search for a particular value in a string then you can use a handy little built in php function called strpos

strpos($theString,$theValue)

So lets say you have a string “I love blogs about programming” and you stored that in a variable called $theString like so:

$theString = “I love blogs about programming”;

You could create a conditional statement to see if the string contains a certain word, and if so you could execute some code

$theString = “I love blogs about programming”;
$theValue= “blog”;

$pos = strpos($theString,$theValue)

if ($pos !== false){
//note condition above !==false
echo “blogging about programming is fun”;
}

VBScript – ASP – Create an Array and Order By Current Month

June 1st, 2010

Recently I came across a problem that I thought would be a straight forward solution however creating Sort Order’s in Classic ASP using VBScript is not a simply task.    Basically what I wanted was to create a rolling list of the Calendar months that would be sorted by current month first, then in it’s usual order for example if the current Month  is May the list should be displayed like so:

  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
  • January
  • February
  • March
  • April

Then the list should dynamically change when the current month changes.    My solution involved creating a function that connects to a table in a database that contains the list of Months associated with and Relevent id:

| Months Table | – -

ID
MonthName
1
January
2
February
3
March
4
April
5
May
6
June
7
July
8
August
9
September
10
October
11
November
12
December

I would then get an Integer value  for the current month, so for example if the current month is May the Integer Value would be 5, you can combine the VBScript functions Month() and Now like so Month(now)to perform this This is then stored in an Array called currentMonthNumber like:

currentMonthNumber = Month(now)

Now you have this value you can create a Do Until Loop and and If then statement to compare the ID’s from the Month’s Table and if they are less than the current Month integer you can add the value of 12 so that now you have a Sort Order id for instance

ID
MonthName SortOrderID
1
January 13
2
February 14
3
March 15
4
April 16
5
May 5
6
June 6
7
July 7
8
August 8
9
September 9
10
October 10
11
November 11
12
December 12

The Month Name  and associated Sort Order ID would then be added to a Dictionary Object (which is a type of array that stores values as a name/value pair)

Once the dictionary object  has stored the values we can do a For Each Loop and add the values to a Disconnected recordset.  The reason we use a disconnected recordet is that it allows us to sort the order of the monthNames by the sortid like so:

monthRst.sort = “sortid ASC”

The full code is shown below:

‘—————————————————–

Function orderMonthByCurrentMonth()

set conn = createobject(“adodb.connection”)

conn.open dsn

set rst = createobject(“adodb.recordset”)

sql = “SELECT * FROM monthNames ORDER BY id ASC”

rst.open sql,conn

Dim monthDictionaryObject, currentMonthNumber, rollingId
Dim monthRst
currentMonthNumber = Month(now)

Set monthDictionaryObject = CreateObject(“Scripting.Dictionary”)
Set monthRst = CreateObject(“adodb.recordset”)

If not rst.eof then
do until rst.eof
If rst(“id”)<currentMonthNumber then
rollingId = rst(“id”) + 12
else
rollingid = rst(“id”)
End if

monthDictionaryObject.add “”&(rst(“monthName”)),”"&rollingid

rst.movenext
loop
end if

monthRst.Fields.Append “month1″, 8, 255
monthRst.Fields.Append “sortid”, 3
‘monthRst.Fields.Append “monthid”, 3
monthRst.Open

For Each item In monthDictionaryObject
monthRst.AddNew
monthRst.Fields.Item(“month1″).Value = item
monthRst.Fields.Item(“sortid”).Value = monthDictionaryObject.item(item)

Next

monthRst.sort = “sortid ASC”

If not monthrst.eof then
do until monthrst.eof
%><li><%=monthRst.Fields.Item(“month1″).Value%></li><%
monthrst.movenext
loop
end if

End Function