Classic ASP - Implementing SMTP authentication in sending emails via CDONTS - email

Below is an already working code in classic ASP to send an email. Can we implement SMTP authentication to this code?
I have implemented using CDO, but would like to know if we can implement SMTP authentication for CDONTS. Please see my code below:
Set objCDO = Server.CreateObject("CDONTS.NewMail")
objCDO.to = "testrecipient#domain.com"
objCDO.From = "testsender#domain.com" 'CustEmail
objCDO.Subject = "Test Subject"
objCDO.BodyFormat = 0
objCDO.MailFormat = 0
objCDO.Body = "This is a test message"
objCDO.Importance = 0 'High importance!
objCDO.Send 'Send off the email!
'Cleanup
Set objCDO = Nothing
ReplySent="Email sent!"
Response.write(ReplySent)
Response.End

Related

Sending email with Classic ASP through Godaddy

I'm trying to send email using Classic ASP from my website at Godaddy. Unfortunately, the cod I have from 10-15 years ago doesn't work (imagine that! lol). Here's the code. Can someone tell me what has changed since then? desperately await your reply. Thank you!
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = false
.Item(cdoSendUserName) = "email#mywebsite.com"
.Item(cdoSendPassword) = "MyPassword"
.Item(cdoURLProxyServer) = "server:25"
'.Item(cdoSendUsingMethod) = cdoSendUsingPickup
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "relay-hosting.secureserver.net"
.Item(cdoURLGetLatestVersion) = True
.Update
End With
'Create mail object
Set cdoMessage = CreateObject("CDO.Message")
'Apply the settings to the message object then send the email
With cdoMessage
Set .Configuration = cdoConfig
.From = "Support (email#mywebsite)"
.To = "The User (user#email.com)"
.BCC = ""
.Subject = "This is a test email."
.TextBody = "This is a test email. If it were a real email there would be some blah blah blah here! This concludes the test of the Godaddy email message."
.Send
End With
'Cleanup mail objects
Set cdoMessage = Nothing
Set cdoConfig = Nothing
Ok folks. This is for the people that need a guiding hand from time to time. However, make sure you enter the right username and password. When hosting on Godaddy you could have up to three different usernames and passwords. You have your Godaddy account username and password (that's not it!), you have a username and password for Plesk (that's not it either!). Then you have a username and password for your primary website (that's the one you want!). Even though you might have several different websites under your hosting, only one will be the primary. Mine was for the email and password that are associated with that prime website. Once you get this code posted you should be good to go. However, you might have to wait a while in order for it to start working. For me it took about 8 hours for the DNS to catch hold of what I was doing and start sending my emails through. Once it did though, now it works great! Enjoy!
Dim objNewMail
'Your email information
Set objNewMail = Server.CreateObject("CDO.Message")
objNewMail.From = "your-email#this-website.com"
objNewMail.Cc = "your-email#this-website.com"
objNewMail.To = "send-to#their-email.com"
objNewMail.Subject = "This is a test email"
objNewMail.TextBody = "this is a test email"
' GoDaddy SMTP Settings
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="relay-hosting.secureserver.net"
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/cdoSendUserName") = "your-primary-website-username"
objNewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/cdoSendPassword") = "your-primary-website-password"
objNewMail.Configuration.Fields.Update
objNewMail.Send
'After the Send method, NewMail Object become Invalid
Set objNewMail = Nothing

How to control tracking options and tags when using Mailgun's SMTP option (i.e. not using their API)

I’m using python to send emails using Mailgun’s SMTP server. I wish to use Mailgun’s builtin ability to tag my messages, and to track open and click events.
I know this can be done using Mailgun’s send message API, by adding headers like o:tag, o:tracking, o:tracking-clicks and o:tracking-opens (as explained here: https://documentation.mailgun.com/en/latest/api-sending.html#sending)
However, seeing as I'm the SMTP gateway and not the API, I’m trying to understand how to achieve the same result - emails that are tagged and fully tracked in Mailgun.
Any thoughts on how it can be done?
This is my little script at the moment:
message = MIMEMultipart("alternative")
message["Subject"] = "This is an email"
message["From"] = “<from email>”
message["To"] = “<to email>”
htmlpart = MIMEText("<html><body>email here!</body></html>", "html")
message.attach(htmlpart)
server = smtplib.SMTP_SSL(“<smtp server>”, 465)
server.ehlo()
server.login(“<username>”, “<password>”)
server.sendmail(from_addr=“<from email>”, to_addrs=“<to email>”, msg=message.as_string())
server.close()
Found it!
The following X-Mailgun headers can be added:
https://documentation.mailgun.com/en/latest/user_manual.html#sending-via-smtp
So my script would be:
message = MIMEMultipart("alternative")
message["Subject"] = "This is an email"
message["From"] = “<from email>”
message["To"] = “<to email>”
message["X-Mailgun-Tag"] = "<tag>"
message["X-Mailgun-Track"] = "yes"
message["X-Mailgun-Track-Clicks"] = "yes"
message["X-Mailgun-Track-Opens"] = "yes"
htmlpart = MIMEText("<html><body>email here!</body></html>", "html")
message.attach(htmlpart)
server = smtplib.SMTP_SSL(“<smtp server>”, 465)
server.ehlo()
server.login(“<username>”, “<password>”)
server.sendmail(from_addr=“<from email>”, to_addrs=“<to email>”, msg=message.as_string())
server.close()
Now my email is tagged (can be analysed on a tag level in Mailgun), and clicks are tracked.
Happy days!

Cannot send mail using smtp.gmail.com from ONLY one specific Google account

I am not able to send mail via smtp.gmail.com for ONLY one specific Google account. When I use another Google account my VBS script sends mail successfully so I know the script is working correctly.
Both accounts have the Less Secure Apps turned ON.
I have also tried the Display Unlock Captcha multiple times.
POP and IMAP has been enabled for both accounts.
It looks like there is an issue with that particular account and I have already posted a request for support in the Gmail help forums.
https://productforums.google.com/forum/#!topic/gmail/8XFKONFbDA8
My VBS Script:
Dim emailObj
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "******#gmail.com"
emailObj.To = "******#gmail.com"
emailObj.Subject = "Test Email"
emailObj.TextBody = "Testing Email Functionality"
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/smtpconnectiontimeout") = 60
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
'First Account
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "******#gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "************"
'Second Account
'emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "******#gmail.com"
'emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "************"
emailConfig.Fields.Update
emailObj.Send
If err.number = 0 Then
Msgbox "Done"
Else
Msgbox err
End If
Account 1 Test (Not Working)
Account 2 Test (Working)
Error Message: The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available
Any help would be appreciated.
I had a same error. There is an option in Google account - https://myaccount.google.com/lesssecureapps. I turned it On and it helped me.

Using CDO/SMTP/TLS in VB6 to send email smtp.office365.com mail server

I am searching for days to find out how can I set Office365 SMTP server in my VB6 application. My code is working properly with port 465 and other mail servers.
BUT it is not working with port 587 and smtp.office365.com
Is there any way I could have TLS via 587 in VB6?
Thanks
With this code, I get to send mail using CDO to Office365.
Private Message As CDO.Message
Private Attachment, Expression, Matches, FilenameMatch, i
Sub enviar_mail()
Set Message = New CDO.Message
Message.Subject = "Test Mail"
Message.From = "YourEmail#yourdomain.com"
Message.To = ""
Message.CC = ""
Message.TextBody = "my text body here"
Dim Configuration
Set Configuration = CreateObject("CDO.Configuration")
Configuration.Load -1 ' CDO Source Defaults
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com"
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "YourEmail#yourdomain.com"
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "YourPass"
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
Configuration.Fields.Update
Set Message.Configuration = Configuration
Message.Send
End Sub
This code worked for me until a few days ago when we switched ISP's (or maybe something changed coincidentally on the server side). If I specify port 587, I get a transport error and have not found the solution for that with VBA. Please let me know if this works for you and if you find a way to use 587. (Port 25 doesn't work for me either, same error.)
Public Function SMTPSend(vSendTo, vsubject As Variant, vmessage As Variant)
'This works
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "name#myemail.com"
emailObj.To = vSendTo
emailObj.Subject = vsubject
emailObj.TextBody = vmessage
'emailObj.AddAttachment "c:\windows\win.ini"
Set emailConfig = emailObj.configuration
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/smtpserver") = "smtp.office365.com"
'Must exclude port if specifying SSL
'emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "name#myemail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword"
emailConfig.Fields.Update
emailObj.Send
If Err.Number = 0 Then SMTPSend = True Else SMTPSend = False
End Function
There seem to be a number of posts on various forums suggesting that the CDO library doesn't work with port 587, but that's not true. I think the real issue is that SMTP services using port 587 are doing so because they require STARTTLS authentication and the http://schemas.microsoft.com/cdo/configuration/smtpusessl config option is specific to SSL, not TLS (I know, I know - not the most accurate description but it'll suffice for now).
Instead, there is another setting - http://schemas.microsoft.com/cdo/configuration/sendtls - that does support TLS, so using this with port 587 works fine:
config.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value = 2 '2 = cdoSendUsingPort
config.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value = "smtp.example.com"
config.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport").Value = 587
config.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate").Value = 1 '1 = cdoBasic
config.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername").Value = "my_username"
config.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword").Value = "myy_very_secret_password"
config.Fields("http://schemas.microsoft.com/cdo/configuration/sendtls").Value = True
config.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout").Value = 60
config.Fields.Update()
This is what worked for me:
flds("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
flds("http://schemas.microsoft.com/cdo/configuration/smtpserver")= "smtp.office365.com"
flds("http://schemas.microsoft.com/cdo/configuration/smtpserverport")= 25
flds("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")= 1
flds("http://schemas.microsoft.com/cdo/configuration/sendusername")= "name#myemail.com"
flds("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypasword"
flds("http://schemas.microsoft.com/cdo/configuration/smtpusessl")= True
flds("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")= 60
I don't know if you could fix it, but I got it with this:
Private Sub Command1_Click()
Dim oSmtp As New EASendMailObjLib.Mail
oSmtp.LicenseCode = "TryIt"
' Set your Hotmail email address
oSmtp.FromAddr = "liveid#hotmail.com"
' Add recipient email address
oSmtp.AddRecipientEx "support#emailarchitect.net", 0
' Set email subject
oSmtp.Subject = "test email from hotmail account"
' Set email body
oSmtp.BodyText = "this is a test email sent from VB 6.0 project with hotmail"
' Hotmail SMTP server address
oSmtp.ServerAddr = "smtp.live.com"
' Hotmail user authentication should use your
' Hotmail email address as the user name.
oSmtp.UserName = "liveid#hotmail.com"
oSmtp.Password = "yourpassword"
' Set port to 25, if you want to use 587 port, please change 25 to 587
oSmtp.ServerPort = 25
' detect SSL/TLS connection automatically
oSmtp.SSL_init
MsgBox "start to send email ..."
If oSmtp.SendMail() = 0 Then
MsgBox "email was sent successfully!"
Else
MsgBox "failed to send email with the following error:" & oSmtp.GetLastErrDescription()
End If
End Sub
Font: https://www.emailarchitect.net/easendmail/kb/vb.aspx?cat=4
Remember download the library:
http://easendmail-smtp-component-net-edition.soft112.com/
Just Replace Parameters!

VBScript that sends an email without an SMTP server?

I'm trying to create a VBS script that sends an alert email when a folder has reached a specific file size, but I can't seem to get it to send an email. I get this error - "The transport failed to connect to the server". Is there any way to send an email without a SMTP server or?
I changed my pswrd/email an stuff for obv reasons.
Const dirPath = "C:\Users\tim.mcgee\Desktop\Offsite Drive"
Const alertedPath = "prevRun.txt"
alertOn = 3 * 2 ^ 29 '1.5GB
resetOn = alertOn * .95 'Approx 77MB
Const emailTo = "**"
Const emailFrom = "**"
Const emailSbjct = "Offsite Drive Full"
Const emailMsg = "The offsite drive has reached maximum capacity."
Const SMTPServer = "Smtp.gmail.com"
Const SMTPPort = 25
emailUsr = emailFrom
Const emailPsswd = "**"
Const emailSSL = False
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(alertedPath) Then
alerted = CBool(Trim(fso.OpenTextFile(alertedPath).ReadLine))
Else
alerted = False
End If
dirSize = fso.GetFolder(dirPath).Size
If alerted Then 'Email previously sent
alerted = dirSize > resetOn
ElseIf dirSize >= alertOn Then
SendEmail
alerted = True
End If
fso.OpenTextFile(alertedPath, 2, True).WriteLine CInt(alerted)
WScript.Quit 0
Sub SendEmail
Const cfg = "http://schemas.microsoft.com/cdo/configuration/"
With CreateObject("CDO.Message")
.From = emailFrom
.To = emailTo
.Subject = emailSbjct
.TextBody = emailMsg
With .Configuration.Fields
.Item(cfg & "sendusing") = 2
.Item(cfg & "smtpserver") = SMTPServer
.Item(cfg & "smtpserverport") = SMTPPort
.Item(cfg & "smtpconnectiontimeout") = 60
.Item(cfg & "smtpauthenticate") = 1
.Item(cfg & "smtpusessl") = emailSSL
.Item(cfg & "sendusername") = emailUsr
.Item(cfg & "sendpassword") = emailPsswd
.Update
End With
.Send
End With
End Sub
The error message means that your script can't connect to smtp.gmail.com on port 25. Nowadays most ISPs don't allow outbound mail on port 25 as a spam prevention measure. You need to send either through one of their mail relays, or the remote server must accept mail on a different port, usually 587 (submission) or 465 (SMTPS, deprecated).
Since you already have credentials you should probably just change the value of SMTPPort to 587 or 465. Gmail should accept authenticated mail on either of those ports.
As for your question about sending mail without an SMTP server, when using CDO you basically have 3 options for sending messages. You select the one you want to use via the sendusing configuration field:
cdoSendUsingPickup (numeric value 1): allows you to send mail without having to specify an SMTP server, but you must have an SMTP server installed on the host where the script is running. With this method the mail is submitted to the local SMTP server via a pickup folder. Does not require authentication, but the SMTP server must be configured to route mail correctly.
Normally, when you have a setup with local SMTP servers, these are configured to send all picked up mail to a central mail gateway/hub, which handles further delivery.
cdoSendUsingPort (numeric value 2, default): allows you to send mail to any SMTP server via the SMTP protocol. Also allows you to provide explicit credentials. With this method you must specify an SMTP server to send the mail to.
cdoSendUsingExchange (numeric value 3): allows you to send mail through the Exchange server of your domain. Requires a domain and an Exchange server, obviously.