Solved

Automate Email through vbscript

Posted on 2013-01-10
13
718 Views
Last Modified: 2013-02-04
Hello,

I have the below email script:

Set fso=CreateObject("Scripting.FileSystemObject")

strSMTP="smtpserver.com"
strSubject="hello"
strRecipient=someone@aol.com,someone@smtpserver.com"
strSender="someone@smtpserver.com"
strBody="Hello"
strAttach="C:\test\testfile.pdf"

If fso.FileExists(strAttach) then
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1    ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTP
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    .Update
End With
With iMsg
    Set .Configuration = iConf
    .To = strRecipient
    .CC = ""
    .BCC = ""
    .From = "<" & strSender & ">"
    .Subject = strSubject
    .TextBody = strBody
    .AddAttachment strAttach
    .Send
End With
Set iMsg = Nothing
Set iConf = Nothing
Else
MsgBox "The specified attachment does not exist"
End if


When I send to an AOL or yahoo account I receive the following error:
"The server rejected one or more recipient address.  The server response was: 553 sorry, that domain isn't in my list of allowed rcpthosts(#5.7.1)"

If I send this from my outlook using the same sender and smtp server it sends fine.  

Any help would be appreciated.

Thank you.
0
Comment
Question by:cbones
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 38765052
First of all port 25 isn't the correct port for AOL, you should use 587 instead.

Besides that the problem is most probably caused by not setting the type of authentication to use. Add the following line after With Flds:
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
0
 
LVL 56

Expert Comment

by:Bill Prew
ID: 38765522
There's a great post on this with some very useful code that handles several common email platforms including AOL here:

http://relevantcodes.com/cdo-send-email-from-yahoo-hotmail-live-aol-or-gmail/

If you don't want to use the code there, at least search the code for "aol" and note the differences, like the use of port 587.

~bp
0
 

Author Comment

by:cbones
ID: 38766782
MacroShadow,

I made those changes but still cannot send to a yahoo or aol user.

Any ideas?
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 27

Expert Comment

by:MacroShadow
ID: 38766821
Can you send to a gmail or hotmail account?
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 38766830
btw, you didn't define the sender's smtp account credentials (i.e. username and password.
0
 

Author Comment

by:cbones
ID: 38766855
strSMTP="smtpserver.com" --> my smtp server i just renamed it.
strSubject="hello"
strRecipient=someone@aol.com,someone@smtpserver.com"
strSender="someone@smtpserver.com" --> my account just renamed it.

I can send internally.  In the same domain, just not out.  
Where would I specify that information in the script?

Thank you
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 400 total points
ID: 38766884
0
 

Author Comment

by:cbones
ID: 38766998
I added that in.  I receive this message:

The transport failed to connect to the server
Code: 80040213
Source:  CDO.Message.1
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 38767194
That indicates a network related error. Your application cannot connect to the mail server specified.

If the smtpserver is valid - and from you question it seems that it is - it may be a firewall or proxy settings, blocking you.

Your User Name (the user name parameter) should be: YourUsername@yourDomain.com
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 38767203
I'll be out 'till sunday.
Good luck!
0
 

Author Comment

by:cbones
ID: 38767358
Thanks MacroShadow.

I added the @mydomain.com to the below line:
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = username@mydomain.com

but when I do that it tells me invalid characters

I'll keep searching.
0
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 100 total points
ID: 38794207
Don't forget to enclose strings in double quotes:
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username@mydomain.com"

Open in new window

0
 

Author Comment

by:cbones
ID: 38852721
I will try the above.

Thank you.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question