10

I'm trying to get an email sent using ASP classic, and am having trouble with SMTP configuration.

The error:

CDO.Message.1 error '80040220' The "SendUsing" configuration value is invalid.

The Code(for the email itself):

Set objMsg = Server.CreateObject("CDO.Message")  
objMsg.From     = "name@name.com"  
objMsg.To       = "themetatron@gmail.com"  
objMsg.Subject  = "Procurement Ally Update"  
objMsg.TextBody = strBody 

The Code I tried to configure with (pt 1):

sch = "http://schemas.microsoft.com/cdo/configuration/"  
Set cdoConfig = CreateObject("CDO.Configuration")   
    With cdoConfig.Fields   
        .Item(sch & "smtpserver") = "127.0.0.1"   
        .update   
    End With   

That didn't work, so I tried:

objMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"  
objMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25  
objMsg.Configuration.Fields.Update 

That also didn't work.

(Yes, I didn't show it, but at the end there's a call to objMsg.Send)

As far as I can tell, the local boxes SMTP service is running and ready to do its duty.

Can anyone help?

Crab Bucket
  • 6,219
  • 8
  • 38
  • 73
matthewdunnam
  • 1,656
  • 2
  • 19
  • 34
  • If anyone found this page wondering how to send an email from Excel using CDO, I threw together a Google Doc [How to Send Email from Excel using Gmail](https://docs.google.com/document/d/1u5VLzCApU3k4-9Vp9LEfqyFZ6u9tAY0avNPYN_1FsN4/edit?usp=sharing) with [code on GitHub gist](https://gist.github.com/bergerjac/7355d4e528fa6c64a02dc494f3d241a1) – Jake Berger Jul 28 '18 at 11:24

2 Answers2

23

If you are specifying an smptserver, be sure to set your 'sendusing' field to 2 (or cdoSendUsingPort) as well:

objMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
objMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMsg.Configuration.Fields.Update 
Corbin March
  • 25,526
  • 6
  • 73
  • 100
1

As the SMTP service is on the localhost it makes more sense to send to pickup directory using SendUsingPickup (1). This will be more efficient than sending over network to port 25.

objMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
objMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\Inetpub\mailroot\Pickup"
objMsg.Configuration.Fields.Update 
user2316116
  • 6,726
  • 1
  • 21
  • 35
  • 1
    both corbin march and this worked. I like this one if you've got a smtp pickup location. note, the 'update' line is critical. You'll keep getting the error until you update. – Tom McDonald May 24 '20 at 21:22