Couldn't send message to SMTP server. Transport Error 0x80040217 - email

I get this error when sending a mail through asp using gmail, I already used ports 465, 587 and 25 with same results
Dim mail
dim email2 as string
dim urlms as string
Dim mail
dim email2 as string
dim urlms as string
mail = CreateObject("CDO.Message")
urlms = "http://schemas.microsoft.com/cdo/configuration/"
mail.Configuration.Fields.Item(urlms & "sendusing") = 2 'enviar usando port
mail.Configuration.Fields.Item(urlms & "smtpserver") = "smtp.gmail.com"
mail.Configuration.Fields.Item(urlms & "smtpserverport") = 465
mail.Configuration.Fields.Item(urlms & "smtpusessl") = True
mail.Configuration.Fields.Item(urlms & "smtpconnectiontimeout") = 60
mail.Configuration.Fields.Item(urlms + "smtpauthenticate") = 1
mail.Configuration.Fields.Item(urlms + "sendusername") = "" 'login
mail.Configuration.Fields.Item(urlms + "sendpassword") = "" 'password
mail.Configuration.Fields.Update
mail.Send

If you are using 2-Step authentication in Google Account then you need to change settings either opt to "Enable Less Secure Apps" or generate app passwords that will be 16 chars and you need to use this in your code instead of your actual gmail password.
https://www.google.com/settings/security/lesssecureapps

It worked like a charm for my own mail server, but It fails with Gmail I don't know why....
Anyway, I tried also without the plus to concatinate and didnt work either, finally I used this:
Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message")
'This section provides the configuration information for the remote SMTP server.
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mail.yoursite.com"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 ' or 587
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
' Google apps mail servers require outgoing authentication. Use a valid email address and password registered with Google Apps.
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="somemail#yourserver.com" 'your Google apps mailbox address
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="yourpassword" 'Google apps password for that mailbox
ObjSendMail.Configuration.Fields.Update
ObjSendMail.To = "someone#someone.net"
ObjSendMail.Subject = "this is the subject"
ObjSendMail.From = "someone#someone.net"
' we are sending a text email.. simply switch the comments around to send an html email instead
'ObjSendMail.HTMLBody = "this is the body"
ObjSendMail.TextBody = "this is the body"
ObjSendMail.Send
Set ObjSendMail = Nothing
http://somee.com/DOKA/DoHelpTopics.aspx?docode=false&thnid=102
And worked like a charm for my server but it didn't work for gmail.

//
// MessageId: CDO_E_LOGON_FAILURE
//
// MessageText:
//
// The transport was unable to log on to the server.
//
#define CDO_E_LOGON_FAILURE 0x80040217L
Also why are you using plus to concatinate the three config items.
Your code Dims everything twice. And it dims things as strings.
You are creating objects without using Set.
I doubt your code runs to generate an error.

Note: The message says LOGON ERROR. Make sure name and password is correct.
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "dc#gail.com"
emailObj.To = "dc#gail.com"
emailObj.Subject = "Test CDO"
emailObj.TextBody = "Test CDO"
Set emailConfig = emailObj.Configuration
msgbox emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver")
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") = "YourUserName"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Password1"
emailConfig.Fields.Update
emailObj.Send
If err.number = 0 then Msgbox "Done"

Related

Send multiple messages in ASP

After an internal form is submitted, I want an email to go to the form-filler with specific information and then a new email sent to the customer with different information. As of right now, with what I have, I can make the first email go, but how do I reset the mailer and do it all over again on the same page?
I can make it work if I double-up the code below, but the AddAddress list doesn't reset. The recipients added in the first iteration will still be on the AddAddress list for the second iteration.
This is what I have so far:
message= "<html><body><table><tr><td>Blah blah blah</td></tr>"
message=message & "<tr><td>Something something.</td></tr>"
message=message & "</table></body></html>"
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "domain-com.mail.protection.outlook.com"
Mail.From = "website#domain.com"
Mail.FromName = "person#domain.com"
Mail.AddAddress "me#domain.com"
Mail.Subject = "Gast Repair. Enter P21 order for: " & request.form("CompanyName")
Mail.Body = message
Mail.IsHTML = True
strErr = ""
bSuccess = False
On Error Resume Next ' catch errors
Mail.Send ' send message
If Err <> 0 Then ' error occurred
strErr = Err.Description
'response.write "<P>" & strErr & "</P>"
else
bSuccess = True
'response.redirect sendto
End If
Thanks for the help!
Why use Persits?
Set ObjSendMail = CreateObject("CDO.Message")
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strOutgoingMailServer
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = strSmtp-auth
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strSmtp-pass
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
ObjSendMail.Configuration.Fields.Update
ObjSendMail.To = "Somebody <somebody#example.com>"
ObjSendMail.Subject = strSubject
ObjSendMail.From = strFromName & " <no-reply#example.com>"
ObjSendMail.ReplyTo = strFromName & " <" & strFromEmail & ">"
ObjSendMail.BodyPart.Charset = "UTF-8"
ObjSendMail.TextBody = strEmailBody
ObjSendMail.TextBodyPart.Charset = "UTF-8"
On Error Resume Next
ObjSendMail.Send
Set ObjSendMail = Nothing
Then write a new strEmailBody (message) and run this code again for the new recipient.
If you have problems sending via SMTP server on Windows server, try installing the free hmailServer software.
The official documentation for the Persits.MailSender COM component provides a few methods;
Reset()
Clears all address, attachment and custom header lists so that a new message can be sent.
ResetAddress()
Clears all address lists so that a new message can be sent. Does not clear attachments, embedded images, custom headers or properties.
There is also
ResetAll()
Same as Reset plus resets all properties to their respective default values.
Note: This will completely reset the Mail object back to its default values.
I would give these a try.

how to spam an email using VBS

So i would like to spam an email to check the spam filters. However, it keeps giving me error messages. Such as
could not connect to STMP server
Please help me to improve this.
Dim User
Dim Pass
Dim Name
Dim Input
Dim Input2
Dim Input3
X=MsgBox("Welcome. To log in Please Click OK and enter your G-mail & pass.",0,"EmailSpamBot V1.0")
User = InputBox("Enter your G-mail:")
Pass = InputBox("Enter Password:"& vbCrLf & ""& vbCrLf & "Please note passwords are NOT stored in this script and are case sensitive.")
Name = InputBox("Enter Name:")
Input = InputBox("Enter e-mail of victim:")
Input2 = InputBox("Enter title:")
Input3 = InputBox("Enter message:")
EmailSubject = (""& Input2)
EmailBody = (""& Input3)
'Const EmailFrom = ""
'Const EmailFromName = ""
Const SMTPServer = "smtp.gmail.com"
'Const SMTPLogon = ""
'Const SMTPPassword = ""
Const SMTPSSL = True
Const SMTPPort = 465
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 = "<" & User & Name & ">"
objMessage.To = "<" & Input & ">"
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") = User
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = Pass
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
do
ObjMessage.Send
loop
Any help would be greatly appreciatied
The error message "could not connect to SMTP server" means that your script couldn't establish a connection to the given port on the remote host. That usually happens when a firewall is blocking access. You can verify that with the telnet command:
telnet smtp.gmail.com 465
If access is blocked you should be getting output like this after the timeout expiered:
Connecting To smtp.gmail.com...Could not open connection to the host, on port 465: Connect failed
A tool like tracetcp might provide further insight as to where the packets are blocked.
However, sending authenticated mail is normally for outbound message submission. If you want to test your own spam filter, you should be sending inbound mail (to port 25).
I figured out the problem, when you enter your email, five minutes or so later you get a security email about a less secure app attempting to access, that is the VBS script, you click on the enable less secure app access, and then it works.

Send email vbscript asp

I have Windows Server 2012 R2 and IIS8.5
I trying to send email via CDo
<%
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 = "mymail#gmail.com"
objMessage.To = "email#gmail.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") = "smtp.gmail.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") = "myemail#gmail.com"
'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypass"
'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
response.write objMessage.Err.number
%>
Response goes more than 84000 ms and I get error
Active Server Pages error 'ASP 0113'
Script timed out
/login.asp
The maximum amount of time for a script to execute was exceeded. You can change this limit by specifying a new value for the property Server.ScriptTimeout or by changing the value in the IIS administration tools.
Sending the same email with same code from VBA is OK without any error.
What is wrong?
At the top of page you have to recall libreries:
<!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows 2000 Type Library" -->
<!--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" -->
<%#LANGUAGE="VBSCRIPT"%>
Then you can try to use this code:
Set email_info = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
Flds(cdoSendUsingMethod) = cdoSendUsingPort
Flds(cdoSMTPServer) = "smtp.domain-name.ext"
Flds(cdoSMTPServerPort) = 25
Flds(cdoSMTPAuthenticate) = cdoAnonymous ' 0
Flds.Update
Set email_info.Configuration = iConf

Sending mail using classic ASP?

I am trying to send mail using classic ASP, but my page contain some error that's why when
upload the page it shows the error that :
500 Internal Server Error
This is the code i am using;
<%
Dim smtpserver,youremail,yourpassword,ContactUs_Name,ContactUs_Tel,ContactUs_Email
Dim ContactUs_Subject,ContactUs_Body,Action,IsError
smtpserver = "smtp.gmail.com"
youremail = "xxxxx.yyyyyy#gmail.com"
yourpassword = "password"
Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message")
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1 'Use SSL for the connection
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "aaaaa.bbbbbb#gmail.com"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
ObjSendMail.Configuration.Fields.Update
ObjSendMail.To = "aaaaa.bbbbbb#gmail.com"
ObjSendMail.CC = "cccccc.dddddd#sunarctechnologies.com"
ObjSendMail.Subject = "Subject"
ObjSendMail.From = "xxxxx.yyyyyy#gmail.com"
ObjSendMail.HTMLBody = "<p>hello</p>"
ObjSendMail.Send
Set ObjSendMail = Nothing
%>
I don't have any idea of classic asp this is just copy paste code from some other source.
Your code looks correct but I'd check wheter gmail only accepts SSL connections on port 465. I believe port 567 is for TLS connections. Alternatively just try port 25.
This question is similar to yours.
You also really need to be able to see the detailed error messages your application is reporting.
Assuming you have access to IIS, the first thing I recommend is to activate server side debugging and send errors to browser on in IIS. An error 500 can mean anything form a missing end if to the object not being found. Having a proper error message to work with will help narrow down the source of the problem.

Classic ASP using Email and Local Server

Basically, I have created a form with a To, From, Subject and Textbody, all named appropriately. What I need to know is what code I need to use Classic ASP to link to a local port, to test my code and send an email,
I have IIS installed at the moment and some other little programs, but I can't get my head around it.
Sending an email in vbscript is usually done in via CDO - example using gmails SMTP server (note the use of configuration/smtpserverport and configuration/smtpusessl)
Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message")
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="info#thedomain.com" '#### Gmail Username (usually full email address)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="password" '#### Gmail Password
ObjSendMail.Configuration.Fields.Update
ObjSendMail.To = ""
ObjSendMail.Subject = ""
ObjSendMail.From = ""
ObjSendMail.TextBody = "Hello World"
ObjSendMail.Send
Set ObjSendMail = Nothing