Whats this LOGON window ? Using VBSCRIPT to send an email message - email

Image --> http://i.stack.imgur.com/bKvVv.jpg
When I use the following script to connect to an exchange mail server to send my email message I am prompted by the above login window asking for domain credentials. How do I automate my script so I dont get that login window. The workstation sending the email isnt joined to an AD domain.
Function sendMail(a,b,c)
set objMsg = CreateObject("CDO.Message")
set objConf = CreateObject("CDO.Configuration")
Set objFlds = objConf.Fields
With objFlds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "email server name"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = a
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = b
.Update
End With
strBody = "Script has finished running, 6005 is finished"
With objMsg
Set .Configuration = objConf
.To = c
.From = c
.Subject = "[AUTO] Script has finished running!"
.TextBody = strBody
.Fields.update
.Send
End With
End Function
sendMail "username","password","my email address"
Thanks
John

With the line
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 2
you are requesting NTLM authentication. This probably causes the login dialog to be displayed.
Please try this instead:
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
This causes the sendusername and sendpassword fields to be used, with "basic authentication". Please note that some email servers are configured to reject "basic authentication".

Related

Sneding SMTP Mail with Office365 from SQL2000 DTS

we have migrated from a shared Exchange email host to Office 365. We have some old SQL2000 DTS Active X scripts (vbscript) sending mail that have quit working now. We are sending using CDO and connecting with SMTP. I don't believe anything on the server or our network have changed, but not 100% sure. Below is the vbscript. We are getting a "transport failed to connect to the server" error on the .Send line. Any ideas on how to fix this?
'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************
Function Main()
'# Get a preconfigured "CDO.Message" object
Set oMail = GetCdoMessageObject()
'# Send email
With oMail
.From = "mailsend#ourdomain.com"
.To = "me#ourdomain.com"
.Subject = "test to cfoster#ourdomain.coml"
.TextBody = "This message was sent from a DTS package."
.HtmlBody = "<div><p>This <i>message</i> was sent from a <b>DTS</b> package.</p></div>"
.Send
End With
'# Clean Up
Set oMail = Nothing
'# Return
Main = DTSTaskExecResult_Success
End Function
Function GetCdoMessageObject()
Dim CdoMessage
Set CdoMessage = CreateObject("CDO.Message")
CdoMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'CdoSendUsingPort
CdoMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="smtp.office365.com"
CdoMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
CdoMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True 'Use SSL for the connection (True or False)
CdoMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
CdoMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'cdoBasic
CdoMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="mailsend#ourdomain.com"
CdoMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="passwordhere"
CdoMessage.Configuration.Fields.Update
Set GetCdoMessageObject = CdoMessage
End Function
I found that if I specified SSL true then I had to comment out the line specifying port 587.

using Windows send-to for creating a one step send to>zip>to email

In another post on Stack Overflow a user named James L. presented a useful script for adding 7-Zip to the Send to Options in Windows. I was wondering how hard it would be to take that same principle one more step by sending the results on to be attached to an email?
Most of the zips I create are done in order to email them and this would cut that down to one click. The only obstacle being that it could not create a self-extracting ".exe" file to be attached.
Here are three scripts you can stich together.
CreateBlankZip.vbs Zipname passed as a parameter, use quotes if spaces in name.
Set Ag=Wscript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(Ag(0), 8, vbtrue)
BlankZip = "PK" & Chr(5) & Chr(6)
For x = 0 to 17
BlankZip = BlankZip & Chr(0)
Next
ts.Write BlankZip
Add folder to zip. DestinationZip SourceFolder
Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")
Set SrcFldr=objShell.NameSpace(Ag(1))
Set DestFldr=objShell.NameSpace(Ag(0))
Set FldrItems=SrcFldr.Items
DestFldr.CopyHere FldrItems, &H214
Msgbox "Finished"
Send mail and attach file.
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "dc#gmail.com"
emailObj.To = "dc#gmail.com"
emailObj.Subject = "Test CDO"
emailObj.TextBody = "Test CDO"
emailObj.AddAttachment "c:\windows\win.ini"
Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MyName"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Ppassword1"
emailConfig.Fields.Update
emailObj.Send
If err.number = 0 then Msgbox "Done"

CDO no longer working on Windows Server at network solutions

I am using a server side script using CDO on Network solution that is now failing with a '500 server error' Have they changed their Windows servers?
This code works fine on some other domains hosted by Network solutions. I tried changing to localhost and the server port to 25 with no luck.
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim cdoConfig, cdoMessage, sch, nProfileID, sFName, sLName, sEmail, sBCC, sFromEmail, sMessage, Optin
nProfileID = Request.Form("profileID")
sFName = Request.Form("fname")
sLName = Request.Form("lname")
sFromEmail = Request.Form("email")
sMessage = Request.Form("message")
Optin = Request.Form("optin")
'sAction = "email_form_work.asp?profileID=" & nProfileID
sEmail = "m.hill#secretagency.com" 'generic email account *** change to info#bglawde.com
sBCC = "hillcreative#comcast.net"
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
'Set CDO Port
.Item(sch & "sendusing") = 1
'Set mailserver name either IP address, mail.yoursite.com or localhost
.Item(sch & "smtpserver") = "smtp.secretagency.com"
'Set SMTP port which is 25 by default
.Item(sch & "smtpserverport") = 2525
'Set number of seconds before timeout
.Item(sch & "smtpconnectiontimeout") = 60
.update
End With
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.From = sFromEmail
.To = sEmail
.CC = ""
'use this to send a blind copy
.BCC = sBCC
.Subject = ""
'Send the email in text format *comment out HTML
.TextBody = sFName & " " & sLName & " has sent you the following message:" & vbCRLF & vbCRLF & sMessage & vbCRLF
.Send
End With
set cdoMessage = nothing
set cdoConfig = nothing
'************ Mail ends here ********************
%>
Problem solved. Network solutions Windows Server will only work with CDO when employing Authentication:
cdoSMTPAuthenticate, cdoSendUsername, cdoSendPassword must be defined.

Send email using CDO no longer working

since last week, I am no longer able to send email via gmail's smtp server. I get the error " -2147220973 the transport failed to connect to the server" whenever I try to send email. However, if I try using my another network (ex. my mobile broadband) it works.
Below is my code for sending email.
Set cdomsg = CreateObject("CDO.Message")
Set cdoconf = CreateObject("CDO.Configuration")
cdoconf.Load -1 ' CDO Source Defaults
Set cdoFields = cdoconf.Fields
With cdoFields
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "example#gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "abc"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Update
End With
What is the possible problem? Thank you.

CDO.Message delivery notification failed

Here is my environment: Windows Server 2003, Microsoft Access 2003, Microsoft VB 6.5
Trying to send email from Access using CDO.Message. Here is the portion of my code:
Private Sub btnTestEmail_Click()
On Error GoTo SendMail_Error:
Dim Mailmsg As Object
Dim mailconf As Object
Dim McFields As Object
Dim strSchemas As String
Set Mailmsg = CreateObject("CDO.Message")
Set mailconf = CreateObject("CDO.Configuration")
Set McFields = mailconf.Fields
strSchemas = "http://schemas.microsoft.com/cdo/configuration/"
With McFields
.Item(strSchemas & "sendusing") = 2
.Item(strSchemas & "smtpserver") = "smtp.gmail.com"
.Item(strSchemas & "smtpserverport") = 465
.Item(strSchemas & "smtpauthenticate") = 1
.Item(strSchemas & "sendusername") = "my_email#gmail.com"
.Item(strSchemas & "sendpassword") = "my_gmail_password"
.Item(strSchemas & "smtpconnectiontimeout") = 60
.Item(strSchemas & "smtpusessl") = 1
.Update
End With
Set Mailmsg.Configuration = mailconf
With Mailmsg
.TextBody = "Test email body text"
.Subject = "Test email subject"
.To = "target_email#gmail.com"
.from = "my_email#gmail.com"
'.AddAttachment "D:\test.pdf"
.Fields("urn:schemas:mailheader:disposition-notification-to") = "my_email#gmail.com"
.Fields("urn:schemas:mailheader:return-receipt-to") = "my_email#gmail.com"
' Set delivery status notification (DSN)
' Name Value Description
' cdoDSNDefault 0 No DSN commands are issued.
' cdoDSNNever 1 No DSN commands are issued.
' cdoDSNFailure 2 Return a DSN if delivery fails.
' cdoDSNSuccess 4 Return a DSN if delivery succeeds.
' cdoDSNDelay 8 Return a DSN if delivery is delayed.
' cdoDSNSuccessFailOrDelay 14 Return a DSN if delivery succeeds, fails, or is
.DSNOptions = 0
.Fields.Update
.Send
End With
MsgBox "Message Sent", vbOKOnly
Set Mailmsg = Nothing
Set mailconf = Nothing
Set McFields = Nothing
Exit Sub
SendMail_Error:
MsgBox Err.Description, vbOKOnly
End Sub
With DSNOptions = 0 works great but I would like to get delivery notification (not read notification).
If I set DSNOptions to any allowed non-zero value the email doesn't even arrives to the target email and I don't get any notification to my email.
Strange thing if I set unexisting target email (on purpose) I get delivery unsuccessful notification even with DSNOptions = 0.
Am I missing something in the code? Found on multiple other web site people claims this code works but using other smtp servers. Any help appreciated.