Dropdownlist Tooltips

Leave a comment

Today i was writing a program, and I ran into a problem where I had DropDownLists drawing data from the database, but the text was really long, thus making the DDL’s stretch halfway accross the page.  After doing a little searching I was able to simply solve it by adding a little code.

Basically what this does is:  in the pre_render section of the dropdownlist control, you

1. Add the “title” attribute to each list item (regardless of size), this way they all have tooltips

2. Scroll through the list items to see how many characters we have

3. If they’re greater than 95, grab the left 95 characters of text, add an elipses

Protected Sub ddlProgramSession6_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlProgramSession6.PreRender

For Each li In ddlProgramSession6.Items

li.Attributes.Add(“title”, li.Text)
If li.Text.Length > 95 Then
Dim strTemp As String
strTemp = Left(li.Text, 95) & “…”
li.Text = strTemp
End If

Next
End Sub

This was an easy way to solve this problem.  Maybe in the future I’ll try to make the elipses into a hyperlink so it’s more intuitive to the user that there is more text.

Yanks Phils

Leave a comment

Please god, we’re one loss away for each team to get knocked out of the playoffs.  That’s the only news I have to look forward to in a long while as a Mets fan.  Yeah, I know we’re getting a new GM, but I’m not going to be excited about a new GM until I see what direction he takes the team. When’s next season start?  I’m ready for it!

Sendmail Connection Refused

Leave a comment

After getting outgoing email to work on my linux box in order to email logs to myself (see  Sendmail1 , Sendmail2, Sendmail3 posts), i decided to try to get incoming email to the linux box to work. FYI This is not my main mail server, i basically use sendmail to send backup log files to other computers..

BTW here’s the OS for my box. it might be a slightly different config on other boxes:

#lsb_release -a

Distributor ID: RedHatEnterpriseES
Description:    Red Hat Enterprise Linux ES release 4 (Nahant Update 4)
Release:        4

I was getting the following error when trying to send an email

Oct 12 09:26:22 mylinuxbox sendmail[3959]: o9CDQM6f003957: to=, delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=120321, relay=mylinuxbox.mydomain.com. [192.168.1.3], dsn=4.0.0, stat=Deferred: Connection refused by mylinuxbox.mydomain.com.

To test locally I used the command:
/usr/sbin/sendmail root@mylinuxbox.mydomain.com

to test remotely i used the command and it was successful:
telnet mylinuxbox.mydomain.com 25

220 mylinuxbox.mydomain.com ESMTP Sendmail 8.13.1/8.13.1; Tue, 12 Oct 2010 10:30:40 -0400

After doing a little research on this i was able to get it to work, by going into the /etc/mail/sendmail.cf file and adding the line (in bold). This allowed sendmail to listen on its ethernet port (192.168.1.3) in addition to localhost :

# SMTP daemon options

O DaemonPortOptions=Port=smtp,Addr=127.0.0.1, Name=MTA
O DaemonPortOptions=Port=smtp,Addr=192.168.1.3, Name=MTA

I then restarted sendmail (#service sendmail restart), performed the test again and everything worked correctly locally, however when i try to connect from my computer on port 25 I would get a connection refused.
C:\Users\me>telnet 192.168.1.3 25
Connecting To 192.168.1.3…Could not open connection to the host, on port 25: Connect failed

However, I realized that if i tried from my my mail server I could connect with no problems. Then i figured out that i had Mcafee Antivirus on my computer, and sure enough it was blocking me from making remote telnet connections to 25. duh.

Halladay No-Hitter

Leave a comment

God I hate the Phillies. Can someone please take them out or at least get a freaken hit against them. Jeez, I don’t think I can take another Phillies/Yankees World Series.

Sendmail Project Part III – Creating the Mail Through a Script

1 Comment

Now that I have Sendmail Started (Part I) and I can successfully send mail to my email address on the local network (Part II), I need to throw information in the email regarding my daily backup. I could use something like Mutt to email the whole backup file to myself, but the logs are 45MB, and that would add up over time, especially since I only need to see a few lines of the log file.

I first create a file called emailbkuplog.sh in /usr/local/sbin which will be the backup script. Then i change the permissions on this to 755 so it can properly be run. then i write the script:
#!/bin/sh
#Program to email backup logs to myself and cc them to whomever
ADDR1=mymailaddress@myemaildomain.com
ADDR2=myccmailaddress@myemailaddress.com
LOGDIR=/home/backup/logs
CURDIR=`pwd`
cd $LOGDIR
#grab last log
LASTLOG=`ls -t *log|head -1`
BUSTATUS=`grep Status= $LASTLOG`

echo `tail -6 LAST_Backup` | mail -s $BUSTATUS -c $ADDR2 $ADDR1
cd $CURDIR

I’ll explain the script above briefly. First i set up some variables to hold my email addresses, location of my backup log, and the current working directory so i can change back to it after the script is done. I then change the current directory to where my logs are. My logs are formatted like so when they are created:
04102010.log,
04112010.log, etc.
so i need a way to figure out which was the last log that was created. I do this by performing an ‘ls -t *.log’ which orders the directory by time, and I grab the first entry (most recent log) by piping it to ‘head -1’ Now that i have the name of the last log, i grab the line in it which gives me the backup status – this will be the subject of the email.

Now to create the email. The format and options that i’m using is like so:

mail -s “Hello” -c

The above alone will send an email with the subject “Hello” to the email address you specify, and CC it

Now I want to put some details into the body. You do this by piping information into the mail command like so.

echo “This is the message body” | mail -s “Hello” -c

My detail come by echoing the results of another file called LAST_Backup which contains more detailed backup information in the last 6 lines of the file, thus here’s my final command to send backup information as the subject, and more detailed info as the message body:

echo `tail -6 LAST_Backup` | mail -s $BUSTATUS -c $ADDR2 $ADDR1

Save the file, and then try to run it by typing it’s name in at a shell prompt.

if successful you will have an email in your inbox with the information you want. if not, you may want to check the mail log files in /var to see if there’s anything that indicates an error.

The last step is to place an entry in your cron file to get it to run on a regular basis. To bring up cron, enter the command “crontab -e” For my purposes, I need this to happen 6 days a week (we’re closed on sunday) Tuesday – Sunday at 7:00 AM. Here’s my entry to do that.

0 7 * * 2-7 /usr/local/sbin/emailbkuplog.sh > /dev/null 2>&1

If you want to understand that > /dev/null 2>&1, here’s a great article that explains what it means here

The above, emails me the status as the subject, and then fills me in on the details in the message body. It works great, and is an easy check on my phone when i’m away from the office as i don’t have ssh to the box, or open a 45mb attachment on my phone.

A few notes about this:

If you wanted to attach the file, there are several programs that will do this for you, just google them, but i don’t think the mail command alone will do this. One of them is using the mutt command, and another is uuencode. There’s plenty of information out there on this. Just google it.

I’ve found that the “echo” command doesn’t hold the format of the file that it echo’s, so if its 3 lines like
line 1
line 2
line 3
echo will output it like “line 1 line 2 line 3”
An alternate to this type of echo format is would be to format it with the “printf” command or so i have read, but it’s beyond what i’m willing to do right now. I wanted something quick and dirty and this did the job.

Hope this helps someone else. Ciao.

Sendmail project Part II – Getting Sendmail to Send Email to Local Email Server

1 Comment

So now that I have sendmail started (Sendmail1 ) everything should work, right? not yet. A little background first, I only need to send this email internally. I have an Exchange 2003 running GFI Mail Essentials 2010. So i first go into Exchange System Manager and into the SMTP Virtual Server and make sure my linux box ip address is allowed to relay. I then go into GFI ME and make sure that my Linux Box IP address is in the white list so nothing would block that server from sending.

I try to do a mail -s “Test” myemail@myemaildomain.com and check my inbox. It didn’t send. I run a ‘tail -f /var/maillog’ in another session to see what errors it’s throwing out there (-f will automatically update the end of the log so you don’t have to keep running the tail command) and then perform the test again. This time i’m getting a few different errors. The most notable is:

Sep 17 13:56:56 mylinuxbox sendmail[10836]: o8FLuXvL005391: to=, delay=1+20:00:21, xdelay=00:00:00, mailer=esmtp, pri=3991610, relay=mylinuxbox.mydomain.com. [192.168.1.3], dsn=4.0.0, stat=Deferred: Connection refused by mylinuxbox.myemaildomain.com.

The problem it seemed was that, even though i’m trying to send it to my exchange email server on my network, sendmail was trying to send the mail to itself. After doing a little searching and performing the following basic network command:

#nslookup
set type=mx
mydomain.com

I noticed a problem immediately. No MX record for my domain was popping up when performing the nslookup above. I then realized that the DNS server that my linux box uses in /etc/resolv.conf had no MX record in it. All my DNS MX records that the world needs to send email to this company are setup externally. Since my exchange server handles all of the internal mail, i never had a reason to set this up.

So the final solution was to place the mx record for myemaildomain.com in my DNS server that my linux box was using. It was then able to correctly find my email server internally. It was an easy solution but took a little while to figure out with the “connection refused” log entry.

Sep 21 10:19:01 mylinuxbox sendmail[26899]: o8LEJ1mX026899: to=myemail@myemaildomain.com, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30050, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (o8LEJ1g6026992 Message accepted for delivery)
Sep 21 10:19:01 mylinuxbox sendmail[27037]: o8LEJ1g6026992: to=, ctladdr= (0/0), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=120309, relay=mymailserver.myemaildomain.com. [192.168.1.8], dsn=2.0.0, stat=Sent ( Queued mail for delivery)

Great, i got the email. Now let’s throw some info in the subject and message so i can get my backup info. Check out Sendmail3