Sunday, June 28, 2009

Using GMail for CDOsys SMTP Relaying

I am in the process of moving one of my externally-hosted web sites to an internal host on my home network.  But one of the problems I’ve been working on is how to continue sending e-mail messages without setting up my own SMTP relay host.  I wanted to be able to make the process portable, so it could be used on any host as long as the server has an active Internet connection.  Thanks to a post on Google Groups, I was able to do this.  I’ve taken that code example and made it into a SUB so it’s a little easier to re-use as well.  A small but useful modification…

'----------------------------------------------------------------
' function: send cdosys message using GMail as SMTP relay host
' from: http://groups.google.com/group/hosted-the-basics/browse_thread/thread/c6cc889c9db0a02b?pli=1
'----------------------------------------------------------------


Sub SendGmail(RecipientEmail, SenderEmail, Subject, msgBody, msgFormat)
On Error Resume Next
Dim SMTPServer, SMTPusername, SMTPpassword
SMTPserver = "smtp.gmail.com"
SMTPusername = "YOU@gmail.com"
SMTPpassword = "YOUR_PASSWORD"
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(sch & "smtpauthenticate") = 1
.Item(sch & "smtpusessl") = True
.Item(sch & "smtpserver") = SMTPserver
.Item(sch & "sendusername") = SMTPusername
.Item(sch & "sendpassword") = SMTPpassword
.Item(sch & "smtpserverport") = 465
.Item(sch & "sendusing") = 2
.Item(sch & "connectiontimeout") = 100
.update
End With
Const cdoSendUsingPickup = "c:\inetpub\mailroot\pickup"
Set cdoMessage = CreateObject("CDO.Message")
Set cdoMessage.Configuration = cdoConfig
cdoMessage.From = SenderEmail
cdoMessage.To = RecipientEmail
cdoMessage.Subject = Subject
If Ucase(msgFormat) = "TEXT" Then
cdoMessage.TextBody = msgBody
Else
cdoMessage.HTMLBody = msgBody
End If
cdoMessage.Send
Set cdoMessage = Nothing
Set cdoConfig = Nothing
If Err.Number <> 0 Then
Response.Write "error: " & _
err.Number & " - " & err.Description & _
"<br /><br />"
End If
End Sub

SendGmail SendTo, SendFrom, Subject, MessageBody, "TEXT"


Be sure to edit the values in RED above before trying to use this.  Also, be sure to use your Gmail account as the SendFrom address value or it may not be delivered successfully.  You can easily modify this to work as VBScript by changing the Response.Write statements to Wscript.Echo, if  you want to.



In case you happen to be a TextPad user (like I am), I have added this to the ASP Clip Library posted on my Scripting Resources site at http://www.steinvb.net/scripting.php  Yes, I know it’s a bit ironic that I post something about ASP on a page written in PHP, but that’s how my brain works anyway.

Friday, June 26, 2009

Scripting Resources Updated - Again

Just a heads-up that I posted updates to the ASP and PHP clip library files for TextPad up on my Scripting Resources site. Major re-write of the PHP clip library. I hope they are useful to you.

Friday, June 19, 2009

Another Milestone

My oldest of four kids graduated high school today. Next one in two years, so I have a little time to prepare again (physically and mentally). The graduation was for Princess Anne High School (aka PAHS) class of 2009, which included 420 seniors. %49 graduated with honors or advanced honors. $4 million in scholarships were awarded also. Not to us though. My daughter will be attending a local community college in August to get on her way to a degree of some kind. Right now she's thinking of education, but who knows. My sister and one of her sons drove down from Richmond, and my mother-in-law and sister-in-law flew in from Michigan as well. It's been a hectic but fun week and a fantastic weekend. My daughter's class left on an overnight cruise and return at 5 AM tomorrow morning.

Thursday, June 4, 2009

Scripting Resources Updated

I have another web site where I maintain a homegrown index of resources related to Windows platform scripting. One of the aspects of that is that I post TextPad clip library files and TextPad syntax definitions for various scripting languages. This (so far) includes ASP, PHP, KiXtart, PowerShell, VBScript and most recently DOS BAT/CMD languages. I don't post and update these for the heck of it. I actually rely on them to do most of my projects and find myself updating them frequently. So I figured it might be of some use to someone, so I post them to the site each time I update them. The web page is at http://www.steinvb.net/scripting.php I hope you find it useful. If you have ideas for improving or adding to it please let me know?

Monday, June 1, 2009

Chrysler Builds a Futuristic Car in 1939


Compliments of John C. Dvorak's blog, posted here. An animation feature for the 1939 World's Fair exhibit.