How to send an email in vb6 using SMTP server - email

How to send an email to vb6 using SMTP server, I tried the below code
but I am getting an error like this
run-time error'-2147220973(80040213)': the transport failed to connect
the server.
Dim x
Public Msg
Public IMsg As New CDO.Message Public IConf As New CDO.Configuration
Private Sub Command1_Click()
x = "http://schemas.microsoft.com/cdo/configuration/"
'lstResults.DataSource = GetMenuItems
IConf.Fields.Item(x & "sendusing") = 2
IConf.Fields.Item(x & "smtpserver") = "smtp.gmail.com"
IConf.Fields.Item(x & "smtpserverport") = 465
IConf.Fields.Item(x & "smtpauthenticate") = 1
IConf.Fields.Item(x & "sendusername") = "parmalattest2017#gmail.com"
IConf.Fields.Item(x & "sendpassword") = "Admin#123456"
IConf.Fields.Item(x & "smtppusess1") = 1
IConf.Fields.Update IMsg.To = "mohanraj.p#twilightsoftwares.com"
IMsg.From = "parmalattest2017#gmail.com"
IMsg.Subject = "Q & Q Statements"
IMsg.Sender = "parmalattest2017#gmail.com" Set
IMsg.Configuration = IConf
IMsg.Send
Exit Sub

Related

Classic ASP Mail - Error send to user and admin

I am sending a mail using CDO.Message. When the user submits a form, the form details to be sent to the Web Site Owner and a Acknowledgement mail to the user. The later is not working for me. I have repeated the same code twice by changing the configuration names, I simply get "Internal Server Error"
My Code (mail to the Web Site Owner)
<%
name = Request.Form ("name")
email = Request.Form ("email")
phone = Request.Form ("phone")
message = Request.Form ("message")
Dim iMsg, iConf, Flds, vSub
Response.CodePage = 65001
Response.CharSet = "utf-8"
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
'sending email with Google Apps Premium SMTP server (with autentication)
schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing") = 2
Flds.Item(schema & "smtpauthenticate") = 1
Flds.Item(schema & "smtpserver") = "localhost"
Flds.Item(schema & "smtpserverport") = 25
Flds.Item(schema & "sendusername") = "info#priceakagri.ru"
Flds.Item(schema & "sendpassword") = "******"
Flds.Update
With iMsg
Set .Configuration = iConf
.BodyPart.Charset = "utf-8"
.To = "info#akagri.ru"
.From = "info#priceakagri.ru"
.Subject="Message from Priceakagri.ru contact page"
.HTMLBody="Здравствуйте! <br><br>You have received an Enquiry from <font color='#337AB7'><b>" & Trim(Request("name")) & "</b></font>.<br><br><br><table><tr><td width='30%' colspan='2' bgcolor='#337AB7'>Message Details</td></tr><tr><td>Name</td><td>" & Trim(Request("name")) & "</td></tr><tr><td>Email</td><td>" & Trim(Request("email")) & "</td></tr><tr><td>Phone</td><td>" & Trim(Request("phone")) & "</td></tr><tr><td>Message</td><td>" & Trim(Request("message")) & "</td></tr></table>"
Set .Configuration = iConf
.Send
End With
set iMsg = nothing
set iConf = nothing
set Flds = nothing
%>
The above code works perfectly for me. If I replicate the same and send user a mail on acknowledgement, I get error. I used the users email as .To and From as - info#priceakagri.ru
I have done this in my earlier sites, where I include a .txt file for the later and still is working for me.
Need help.
Regards,
Badri

Error sending email from VBScript

When running the following script I get the errors -2147220975 and Transport code error: 0x80040217
on error resume next
Const schema = "http://schemas.microsoft.com/cdo/configuration/"
Const cdoBasic = 1
Const cdoSendUsingPort = 2
Dim oMsg, oConf
Set oMsg = CreateObject("CDO.Message")
oMsg.From = "tom.watt.vulpes#gmail.com"
oMsg.To = "tom.watt.vulpes#gmail.com"
oMsg.Subject = "Test from VBScript"
oMsg.TextBody = "If you can read this, the script worked!"
objMsg.AddAttachment "C:\BLA_BLA.txt"
Set oConf = oMsg.Configuration
oConf.Fields(schema & "smtpserver") = "smtp.gmail.com"
oConf.Fields(schema & "smtpserverport") = 465
oConf.Fields(schema & "sendusing") = cdoSendUsingPort
oConf.Fields(schema & "smtpauthenticate") = cdoBasic
oConf.Fields(schema & "smtpusessl") = True
oConf.Fields(schema & "sendusername") = "tom.watt.vulpes#gmail.com"
oConf.Fields(schema & "sendpassword") = "PASSWORD"
oConf.Fields.Update()
oMsg.Send()
If Err Then
resultMessage = "ERROR " & Err.Number & ": " & Err.Description
Err.Clear()
Else
resultMessage = "Message sent ok"
End If
Wscript.echo(resultMessage)
I've tried countless scripts from the internet but none of them seem to work. What am I doing wrong?
Thanks, Tom
EDIT: I am running Windows 10
Transport code error: 0x80040217 can be a few different things depending on the situation. The links below should guide you in the right direction...
Overflowing Stack
MSDN
Something that I have found that may help in relation to this was that the domain I was wanting to use this script for had a SPF record with a hard fail attached to it and so then only their specific email server would work with this which in my case was Office 365 but when testing I was using their ISP and attempting to relay unauthenticated through them.
So check SPF also, hope this helps.
Cozzie

ASP Contact form error Server object error 'ASP 0177 : 800401f3'

One of my websites contact/reservations form has suddenly stopped working and I now receive the following error.
Server object error 'ASP 0177 : 800401f3'
Server.CreateObject Failed
/contact2.asp, line 51
I've done a bit of research and it seems to relate to classic ASP commands but
my knowledge of ASP is limited.
Here is the full code:-
<%
name = request.form("name")
email = request.form("email")
phone = request.form("phone")
guests = request.form("guests")
datum2 = request.form("datum2")
info = request.form("info")
time_hour = request.form.item("time_hour")
time_minute = request.form.item("time_minute")
moda_event = request.form.item("modaEvent")
sign_up = request.form.item("signup")
If name="" or email="" Then
url = "reservations.asp?reqd=* indicates required field&name=" & mname & "&email=" & memail
If name="" Then
url = url & "&mname=*"
End if
If email="" Then
url = url & "&memail=*"
End if
response.redirect url & "&foobar=foobar#form"
response.end
End if
Dim objCDONTS ' Email object
Dim strFromName ' From persons' real name
Dim strFromEmail, strToEmail ' Email addresses
Dim strSubject, strName, strPhone, strEmail, strGuests, strDate, strHour, strMinute, strEvent, strInfo, strSignup 'Message
Dim misccompo
strSubject = "Reservation Form"
strFromName = Trim(Request.Form("name"))
strFromEmail = Trim(Request.Form("email"))
strToEmail = "reservations#modarestaurant.co.uk"
strName = Trim(Request.Form("name"))
strPhone = Trim(Request.Form("phone"))
strEmail = Trim(Request.Form("email"))
strGuests = Trim(Request.Form("guests"))
strDate = Trim(Request.Form("datum2"))
strHour = Trim(Request.Form.Item("time_hour"))
strMinute = Trim(Request.Form.Item("time_minute"))
strEvent = Trim(Request.Form.Item("moda_event"))
strInfo = Trim(Request.Form("info"))
strSignup = Trim(Request.Form.Item("signup"))
Set objCDONTS = Server.CreateObject("CDONTS.NewMail")
objCDONTS.From = strFromName & " <" & strFromEmail & ">"
objCDONTS.To = strToEmail
objCDONTS.Subject = strSubject
objCDONTS.Body = "--------------------------------------" & vbcrlf & vbcrlf & "Name: " & strName & vbcrlf & "Contact Number: " & strPhone & vbcrlf & "Email Address: " & strEmail & vbcrlf & "No. of Guests: " & strGuests & vbcrlf & "Date: " & strDate & vbcrlf & "Time: " & strHour & ":" & strMinute & vbcrlf & "Event: " & strEvent & vbcrlf & "Additional Info: " & vbcrlf & strInfo & vbcrlf & "Newsletter Signup: " & strSignup &vbcrlf & "--------------------------------------------------------------" & vbcrlf & "MESSAGE ENDS: End of info"
objCDONTS.Send
Set objCDONTS = Nothing
response.redirect "thank-you.asp"
response.end
%>
The line 51 error is this line;
Set objCDONTS = Server.CreateObject("CDONTS.NewMail")
Any help would be greatly appreciated.
The error
Server object error 'ASP 0177 : 800401f3'
Server.CreateObject Failed
/contact2.asp, line 51
means that the object could not be created because it could not find the appropriate DLL for the object requested. In other words, it is looking for the CDONTS COM component that was included with NT SP4 as the file cdont.dll. CDONTS was deprecated in Windows 2000 and completely removed in Windows 2003. Therefore, if you are using Window 2003, Windows 2008 or Windows 2012 server this error makes sense since the DLL is not present.
To fix this problem try the following - use CDOSYS. CDOSYS (cdosys.dll) is a library file provided as part of IIS for Windows 2000, Windows 2003 Server, and Windows 2008 Server. This DLL enabled applications to route SMTP messages across multiple platforms and added much more functionality over the older CDONTS library.
Here is a greatly simplified example to model some changes on
Dim Message As New CDO.Message
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
with cdoConfig.Fields
.item(sch & "sendusing") = 2
.Item(sch & "smtpserver") = "mail.xxxx.com" ' your SMTP mail server
.Item(sch & "smtpserverport") = 2525
.update
end with
'Create CDO message object
Set Message = CreateObject("CDO.Message")
With Message
set .configuration = cdoConfig
'Set email adress, subject And body
.From = strFromName
.To = strToEmail
.Subject = strSubject
.TextBody = TextBody
'Send the message
.Send
End With

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

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"

How to send outlook mails without opening outlook in PC by testcomplete

i am trying to send outlook mail using vb script language in testcomplete. i am able to send but if the outlook is opened in my PC then only mail will be sent and if the oulook is not opened in my pc,my mail will not be sent untill opening the outllok even after executing this script
here is my code:
Function SendMail
Dim objOutLook, NamespaceMAPI,objNewMail, fso, SendReceiveControls
Dim strTo,strCc ,strBcc ,strSubject, AccountName,strAttachmentPath
strSubject="test"
strTo=yyy#yy.com
strCc=XXX#XX.com
strBcc =zzz#zzz.com
strAttachmentPath="c:\text.txt"
If strTo ="" and strCc = "" and strBcc =""Then
Exit function
ElseIf strSubject =""Then
Exit function
End If
Set objOutLook = CreateObject("Outlook.Application")
Set NamespaceMAPI = objOutLook.GetNamespace("MAPI")
Set objNewMail = objOutLook.CreateItem(olMailItem)
objOutLook.DisplayAlerts =True
objNewMail.TO = strTo
objNewMail.CC = strCc
objNewMail.BCC=strBcc
objNewMail.Subject = strSubject
objNewMail.Body = strMsg
If strAttachmentPath <> "" Then
Set fso =CreateObject("Scripting.FileSystemObject")
If fso.FileExists(strAttachmentPath) Then
objNewMail.Attachments.Add(strAttachmentPath)
objNewMail.display
Else
msgbox "Attachment File Does not exists"
End If
End If
AccountName="XXXXXX#XXXX.com"
' Finding the "Send/Receive" control
Set SendReceiveControls = NamespaceMAPI.GetDefaultFolder("Inbox")._
CommandBars("STANDARD").Controls("Send/Receive")
Set Item = Nothing
'msgbox "send:"&SendReceiveControls.Controls.Count
For I = 1 To SendReceiveControls.Controls.Count
If InStr(SendReceiveControls.Controls(I).Caption, AccountName) > 0 Then
Set Item = SendReceiveControls.Controls(I)
'msgbox "send1"&SendReceiveControls.Controls(I)
Exit For
End If
Next
' Executing the "Send/Receive" action
Item.Controls(1).Execute()
objOutLook.Quit
''''''' Releasing objects '''''''
Set objOutLook =Nothing
Set objNewMail = Nothing
Set fso = Nothing
End Function
please suggest me how to handle this...thanks in advance
Do you really need to send it with outlook?
I use this javascript code to send the email, then, in outlook, you just need to mark it as not spam, otherwise, it goes directly to the spam inbox
function SendEmail(mFrom, mTo, mSubject, mBody, username, password)
{
var i, schema, mConfig, mMessage;
try
{
schema = "http://schemas.microsoft.com/cdo/configuration/";
mConfig = Sys.OleObject("CDO.Configuration");
mConfig.Fields.Item(schema + "sendusing") = 2; // cdoSendUsingExchange
mConfig.Fields.Item(schema + "smtpserver") = "STMP SERVER ADDRESS HERE"; // SMTP server
mConfig.Fields.Item(schema + "smtpserverport") = 25; // Port number
mConfig.Fields.Item(schema + "smtpauthenticate") = 1; // Authentication mechanism
mConfig.Fields.Item(schema + "sendusername") = username; // User name (if needed)
mConfig.Fields.Item(schema + "sendpassword") = password; // User password (if needed)
mConfig.Fields.Update();
mMessage = Sys.OleObject("CDO.Message");
mMessage.Configuration = mConfig;
mMessage.From = mFrom;
mMessage.To = mTo;
mMessage.Subject = mSubject;
mMessage.HTMLBody = mBody;
mMessage.Send();
}
catch (exception)
{
Log.Error("E-mail cannot be sent", exception.description);
return false;
}
Log.Message("Message to <" + mTo + "> was successfully sent");
return true;
}
Try objNewMail.Body.Send instead of trying to execute the send and receive button. Here's a simple example:
Function SendMail()
Dim objOutlook, objNewMail
Set objOutLook = CreateObject("Outlook.Application")
Set objNewMail = objOutLook.CreateItem(olMailItem)
objNewMail.TO = "myrecip#test.com"
objNewMail.Subject = "test"
objNewMail.Body = "test"
objNewMail.Send
End Function