2012-10-10 33 views
5

Có một số mẹo để làm cho VBScript CDO hoạt động với Amazon SES SMTP không? Tôi không nhận được bất kỳ lỗi nào, nhưng nó cũng không gửi cho tôi e-mail thử nghiệm của tôi. Thay đổi SSL thành False không cho tôi lỗi 530, vì vậy tôi biết ít nhất tôi cũng đến được máy chủ. Tôi đang làm gì sai?Có một số mẹo để làm cho VBScript CDO làm việc với Amazon SES SMTP không?

EmailSubject = "Sending Email by CDO" 
EmailBody = "This is the body of a message sent via" & vbCRLF & _ 
     "a CDO.Message object using SMTP authentication." 

Const EmailFrom = "[email protected]" 
Const EmailFromName = "Me Test" 
Const EmailTo = "[email protected]" 
Const SMTPServer = "email-smtp.us-east-1.amazonaws.com" 
Const SMTPLogon = "xxxxxx" 
Const SMTPPassword = "xxxxxxx" 
Const SMTPSSL = True 
Const SMTPPort = 25 

Const cdoSendUsingPickup = 1 'Send message using local SMTP service pickup directory. 
Const cdoSendUsingPort = 2 'Send the message using SMTP over TCP/IP networking. 

Const cdoAnonymous = 0 ' No authentication 
Const cdoBasic = 1 ' BASIC clear text authentication 
Const cdoNTLM = 2 ' NTLM, Microsoft proprietary authentication 

' First, create the message 

Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = EmailSubject 
objMessage.From = """" & EmailFromName & """ <" & EmailFrom & ">" 
objMessage.To = EmailTo 
objMessage.TextBody = EmailBody 

' Second, configure the server 

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

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

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

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

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

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

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

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

objMessage.Configuration.Fields.Update 

' Now send the message! 

objMessage.Send 

Trả lời

7

CDO không hỗ trợ TLS, nhưng chỉ SSL. AWS SES sẽ cho phép bạn sử dụng SSL qua cổng TCP 465. Cố gắng sử dụng SSL qua cổng 25 như bạn có trong tập lệnh bạn đã đăng sẽ trả lại thông báo lỗi sau:

CDO.Message.1: Phương tiện bị mất kết nối với máy chủ.

Tôi không biết tại sao bạn không gặp lỗi đó với tập lệnh này. Tôi làm. Hãy thử thay đổi cổng thành 465. Khi tôi thay đổi cổng thành 465, nó hoạt động.

0

Đây là một thói quen tuyệt vời. Bạn cần phải tuyên bố objMessage như một đối tượng:

Dim objMessage như Object

Ngoài ra, kể từ khi ông đang sử dụng Const, nếu bạn muốn thay đổi bất kỳ của các mặt hàng này, bạn sẽ cần phải khai báo như dây đàn và loại bỏ các Const từ những dòng đó. Tôi đã phải thay thế 465 cho SMTPPort, sử dụng id SES của tôi/pw, và nó hoạt động hoàn hảo!

Các vấn đề liên quan