Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3040
  • Last Modified:

Sending CDO SMTP Mail via gmail

I need to convert my email send capabilities of my web site to use my gmail account.  I could use some help modifying this code to work.  Thanks!!

			Set cdoConfig = CreateObject("CDO.Configuration")
			With cdoConfig.Fields
				.Item(cdoSendUsingMethod) = cdoSendUsingPort
				.Item(cdoSMTPServer) = "old.server"
				.Item(cdoSMTPAuthenticate) = 1
				.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
				.Item(cdoSendUsername) = "your_mom"
				.Item(cdoSendPassword) = "pwd"
				.Update
			End With

			Set cdoMessage = CreateObject("CDO.Message")
			With cdoMessage
				Set .Configuration = cdoConfig
				.To = sEvntDirEmail
				.From = sEmail
				.Subject = sEventName & " Contact: " & sSubject
				.TextBody = sMsg
				.Send
			End With
			Set cdoMessage = Nothing

Open in new window

0
Bob Schneider
Asked:
Bob Schneider
  • 8
  • 7
  • 5
7 Solutions
 
Wayne BarronCommented:
This is what I use.

Pay attention to the top part, it is a secure socket layer connection.

Set myMail = CreateObject("CDO.Message") 
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="smtp.gmail.com"
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true 'Use SSL for the connection (True or False)
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
     
' If your server requires outgoing authentication uncomment the lines bleow and use a valid email address and password.
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="webmaster@domain.com"
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="**********"

myMail.Configuration.Fields.Update

Open in new window


Carrzkiss
0
 
Scott Fell, EE MVEDeveloperCommented:
Your outgoing server is smtp.gmail.com

Just use this for one off's.  If you send bulk through gmail your account will probably get closed.  

This is a great resource  http://www.paulsadowski.com/wsh/cdo.htm  Look for the code that uses, "Sending a text email using authentication against a remote SMTP server."

Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. 
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). 

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "Example CDO Message" 
objMessage.From = """Me"" <me@my.com>" 
objMessage.To = "test@paulsadowski.com" 
objMessage.TextBody = "This is some sample message text.." & vbCRLF & "It was sent using SMTP authentication."

'==This section provides the configuration information for the remote SMTP server.

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.your.com"

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid"

'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 

'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send

Open in new window

0
 
Bob SchneiderCo-OwnerAuthor Commented:
Ok padas, I tried that but got a "Name Redefined" error on this line:

Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.

Except I know it is not elsewhere in the page.  Could it be from this portion of my global.asa page?

<!-- 
METADATA 
TYPE="typelib"
UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
NAME="CDO for Windows 2000 Library"
-->

Here is my entire code:
            Const cdoSendUsingPickup = 1 
            Const cdoSendUsingPort = 2
            Const cdoAnonymous = 0 
            Const cdoBasic = 1
            Const cdoNTLM = 2

            Set objMessage = CreateObject("CDO.Message") 
            objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
            objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
            objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
            objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your_mom"
            objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "pwd"
            objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
            objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
            objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
            objMessage.Configuration.Fields.Update
            objMessage.Subject = sSubject 
            objMessage.From = sEmail 
            objMessage.To = "bobs@h51software.net" 
            objMessage.TextBody = sMsg
            objMessage.Send

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Wayne BarronCommented:
Give this a shot, this is your code, edited to take on the Gmail stuff, just like what I posted.

With cdoConfig.Fields
				.Item(cdoSendUsingMethod) = cdoSendUsingPort
				.Item(cdoSMTPServer) = "smtp.gmail.com"
				.Item(cdoSMTPAuthenticate) = 1
				.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
				.Item(cdoSendUsername) = "your_mom"
				.Item(cdoSendPassword) = "pwd"
				.Update
			End With

Open in new window

0
 
Scott Fell, EE MVEDeveloperCommented:
It looks that way.  I have always used that example.  Just in case other pages are using that, I would just eliminate the portion of the new code that errors.  Here is what 1and1 has.http://faq.1and1.com/scripting_languages_supported/asp_active_server_pages/6.html
0
 
Wayne BarronCommented:
I will repeat this one more time.
The code that I posted, picks up on the SSL Port, that GMail runs from.
GMail does not use port 25.

Please look at my code example again, and give it a shot.
0
 
Bob SchneiderCo-OwnerAuthor Commented:
carrzkiss, I will look at it in the morning....heading to bed...your persistence is much appreciated!!!
0
 
Scott Fell, EE MVEDeveloperCommented:
Carzkiss is right about the port and ssl.  However, the initial problem was the name redefined thing.

When you get this working, I like to put this into a function on a separate page and bring it in as an include file to use everywhere.
<%
theHTML="some html"
theHTML=theHTML&"some  more  html"
'call function to send mail and wrap in template
SendMail (mybuddy@someplace.com ,me@mydomain.com ,"some subject" ,theHTML)
%>
<%
Function SendMail(To,From,Subject,body)

' cdo code above
objMessage.htmlBody = template_1(body) 'wrap template around our content

End function
%>
Even fancier... make a template as an include file

<%
' this is also on a separate asp page as an include file so you can change the template quickly and call it from the code above.
 
function template_1(content)
html=""
html=html&"<table>"
html=html&"<tr><td><img src=""http://fullurl/to_header_image.jpg""></td><tr>"
html=html&"<tr><td>"&content&"</td><tr>"
html=html&"<tr><td>footer stuff.  address city st zip</td><tr>"
html=html&"</table>"
end function
%>
0
 
Bob SchneiderCo-OwnerAuthor Commented:
carzkiss, I got a "Transport can't connect to the server..." error.  I even reset my password to ensure that I had that correct.  Any ideas?
0
 
Wayne BarronCommented:
smtpusessl") = true

With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "smtp.gmail.com"
.Item(cdoSMTPAuthenticate) = 1
.Item(http://schemas.microsoft.com/cdo/configuration/smtpusessl)=true ' If use SSL set to True, if not, set to False
.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item(cdoSendUsername) = "your_mom"
.Item(cdoSendPassword) = "pwd"
.Update
End With

Open in new window


You need the smtpusessl. (5th line above)
http://kb.cffcs.com/Main.asp?irid=199&Type=Article

Carrzkiss
0
 
Bob SchneiderCo-OwnerAuthor Commented:
Perfect!  Thanks!!  I will now spend the time to change all of my web code to reflect this.  padas, thanks for the include idea.  Here is my last question: I use includes for my headers, menus, etc.  How can I stick an include inside a block of asp script????
0
 
Bob SchneiderCo-OwnerAuthor Commented:
Excellent!  Thanks!!
0
 
Wayne BarronCommented:
<%if something="else" then%>
<!--#include file="get.asp"-->
<%else%>
<!--#include file="it.asp"-->
<%end if%>

You cannot put it like this.

<%if something="else" then
<!--#include file="get.asp"-->
%>

So, do the first one set above, and you will be good to go.
(this is the way I do mine, I have as many as 100+ files per project, and everything is included, depending on Queries from the database (or) URL)

Have a good one.
Carrzkiss
0
 
Bob SchneiderCo-OwnerAuthor Commented:
So if I have:
<%
lots
and
lots
of
lines
of
code
%>

I can break it anywhere to insert an include?

<%
lots
and
lots
>%
<!--#include file="get.asp"-->
<%
of
lines
of
code
%>
0
 
Wayne BarronCommented:
Absolutely!

Lets say that you have a page, and within that page, you have 1000 lines of code.
Database Connections.
Page Layout
exc...

You can do it like this.
(Lets just say that you are using tables, as this is 90% of my work, I am trying to convert over to DIV, however, it is a slow process)

<table>
<tr>
<%if request.QueryString("Admin") then%>
<td>Admin Menu</td>
<%elseif request.QueryString("Admin") then%>
<td>Normal Menu</td>
<%end if%>

<%if rs("stack")="Even" then%>
<td>Your stacked content is here</td>
<%elseif rs("stack")="OffSet" then%>
<td>Your stacked content is going to fall off the face of the earth</td>
<%end if%>


<%if rs("Ads")="User1" then%>
<td>1st Right Ads</td>
<%elseif rs("Ads")="User2" then%>
<td>2nd Right Ads</td>
<%end if%>
</table>

Open in new window


With the above scenario, it first deals with a Querystring, to see which menu to show.
Then we look at Database records to see which content to show.
Then we also check the Database records, to see which ads to show which user.

It is that simple, and makes for really easy debugging.

You can find more example here
http://www.cffcs.com

Let me know if you need any more advice on this Dynamic Coding Subject.
I live for this type of projects :)

Carrzkiss
0
 
Bob SchneiderCo-OwnerAuthor Commented:
Incredibly helpful!  Thanks for going above and beyond on this one!!!
0
 
Wayne BarronCommented:
No problem.
I know sharing the Knowledge that I know, when I am able to.
0
 
Scott Fell, EE MVEDeveloperCommented:
I hope you guys are on the east coast - much too early!  Good luck!
0
 
Wayne BarronCommented:
Yep, East coast for me.
Woke up at 3:30am, and laid back down around 8:00am, and just got back up about 30 minutes ago.
0
 
Scott Fell, EE MVEDeveloperCommented:
Ha, I do that too.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now