'Object Required' to send Email - email

I'm trying to make a function so that it sends an email to an Email address which is in one of my queries (UpcomingBirthday). I've got this code in a function and then in a macro autoexec so it runs when I load my database.
Public Function EmailSend()
Dim imsg As Object
Dim iconf As Object
Dim flds As Object
Dim schema As String
Set imsg = CreateObject("CDO.Message")
Set iconf = CreateObject("CDO.Configuration")
Set flds = iconf.Fields
schema = "http://schemas.microsoft.com/cdo/configuration/"
flds.Item(schema & "sendusing") = cdoSendUsingPort
flds.Item(schema & "smtpserver") = "smtp.live.com"
flds.Item(schema & "smtpserverport") = 25
flds.Item(schema & "smtpauthenticate") = cdoBasic
flds.Item(schema & "sendusername") = "MyEmail#hotmail.com"
flds.Item(schema & "sendpassword") = "MyPassword"
flds.Item(schema & "smtpusessl") = False
flds.Update
With imsg
Call EmailSend(UpcomingBirthday.[Email], "MyEmail#hotmail.com", "Birthday Promotion!", "<html>Happy Birthday! <p> Our records indicate that you're eligible for a birthday promotion.</p></html.")
Set .Configuration = iconf
.Send
End With
Set iconf = Nothing
Set imsg = Nothing
Set flds = Nothing
End Function
Now when I try to run this code, it tells me "Run-Time Error 424 - Object Required" and highlights this line when I go to Debug: Call EmailSend(UpcomingBirthday.[Email], "MyEmail#hotmail.com", "Birthday Promotion!", etc.. So what I need it to do is that the values from the column 'Email' in my query 'UpcomingBirthday' and then send an email to them.
If anyone could help me by telling me what I need to do to fix this error that'd be great! And also if you could just scan the code and see if it's fine (as in should it work)? Thanks! :)

The Call EmailSend statement within Public Function EmailSend is clearly problematic. If you want to assign values to the properties of imsg (a CDO.Message object) then just do something like
With imsg
.To = "recipient#example.com"
.From = "MyEmail#hotmail.com"
.Subject = "Birthday Promotion!"
'' and so on
.Send
End With
Also, we don't know what UpcomingBirthday really is because it is defined elsewhere.
You might want to save yourself some bother and just use the SendEmail function available for download here:
http://www.cpearson.com/excel/Email.aspx

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.

When I try to run this VB Script it says "object required" and I cannot find an error

Dim objMessage
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "ALARMNO SPOROĆILO Z NADZORNEGA SISTEMA"
objMessage.From = "someemail#hotmail.com"
objMessage.To = "toemail#hotmail.com"
objMessage.HTMLBody = "Zdravo"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "someemail#gmail"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "00000000000000"
objMessage.Configuration.Fields.Update
REM Now send the message
On error Resume Next
Obj.Message.Send
IF err.Number <> 0 Then
MsgBox Err.Description,16,"Error sending Mail "
Else
MsgBox " Message sent "
END IF
I wrote this code in Notepad++ and saved it as a .vbs file and try to run it, but I get "object required" error. I cannot find the problem.
'Create the objects require for sending email using CDO
Set objMail = CreateObject("CDO.Message")
Set objConf = CreateObject("CDO.Configuration")
Set objFlds = objConf.Fields
'Set various parameters and properties of CDO object
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'cdoSendUsingPort
'your smtp server domain or IP address goes here such as smtp.yourdomain.com
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
'uncomment next three lines if you need to use SMTP Authorization
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "email#gmail.com"
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'cdoBasic
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
objFlds.Update
objMail.Configuration = objConf
objMail.From = "email#gmail.com"
objMail.To = "email#hotmail.com"
objMail.Subject = "Put your email's subject line here"
objMail.TextBody = "Your email body content goes here"
objMail.Send
'Set all objects to nothing after sending the email
Set objFlds = Nothing
Set objConf = Nothing
Set objMail = Nothing
With little more search i found this on the internet...and it works so if anybody else needs a solution here it is ...also if there is somebody who could explain me where i went wrong in my own script...i would be grateful.
I suspect your original script failed because you had
Obj.Message.Send
... instead of
objMessage.Send

Send to mail recipient vbscript not longer working

I used to use below VBscript to send files by mail as attachments to be able to add my signature in the e-mail message.
Since about two weeks the VBscript is showing an error every time I try to send a file. I tried to use normal "send to/mail recipient" and it works fine.
Would you advice how can this be solved?
Code:
Option Explicit
Dim objArgs, OutApp, oNameSpace, oInbox, oEmailItem, olMailItem
Dim a, oAttachments, subjectStr, olFormatHTML
olMailItem = 0
olFormatHTML = 2
Set objArgs = WScript.Arguments 'gets paths of selected files
Set OutApp = CreateObject("Outlook.Application") 'opens Outlook
Set oEmailItem = OutApp.CreateItem(olMailItem) 'opens new email
For a = 0 to objArgs.Count - 1
Set oAttachments = oEmailItem.Attachments.Add(objArgs(a))
subjectStr = subjectStr & Right(objArgs(a),Len(objArgs(a))-(InStrRev(objArgs(a),"\"))) & ", " 'recreates the default Subject e.g. Emailing: file1.doc, file2.xls
Next
If subjectStr = "" then subjectStr = "No Subject "
oEmailItem.Subject = "Emailing: " & Left(subjectStr, (Len(subjectStr)-2))
oEmailItem.BodyFormat = olFormatHTML
oEmailItem.Display
Error message:
Unable to execute - arguments list is too long

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

Is CDO Email the best way to send email using classic asp?

I am using asp to create a webpage that is supposed to send email to several clients. It was suggested that I use CDO email functionality. Is this the best solution for a classic asp webpage? Or would it be better to add asp.net and ajax for handling email this type of thing.
CDO would be the obvious route. In some versions of the .Net Framework ASP.Net would just be using a wrapper around CDO anyway.
I have no clue where Ajax fits into this topic.
Crude and rude (better to reference the library in global.asa to get type info and avoid the long Field ID strings and magic numbers) example copy/pasted and not verified by me:
<%
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
.Item(sch & "smtpserver") = "<enter_mail.server_here>"
.Update
End With
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.From = "from#me.com"
.To = "to#me.com"
.Subject = "Sample CDO Message"
.TextBody = "This is a test for CDO.message"
.Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing
%>
Are you wanting to add Ajax to ClassicASP? I would say you are asking for trouble. If at all possible, I would encourage the customer to move to .net technology. They will be thankful in the long run.
As far as CDO objects, try out this link How do I send e-mail with CDO?
It works this way on ASP Classic using CDO on GoDaddy hosting :
<%
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") ="relay-hosting.secureserver.net"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
ObjSendMail.Configuration.Fields.Update
'ObjSendMail.AddAttachment mPath, "Logo.gif"
'ObjSendMail.AddAttachment ArrwPath, "red_arrw.gif"
ObjSendMail.Subject = strSub
ObjSendMail.To = strTo
ObjSendMail.From = strFrom
ObjSendMail.Bcc = strBcc
ObjSendMail.Cc = strCc
ObjSendMail.HTMLBody = strMsg
ObjSendMail.Send
Set ObjSendMail = Nothing
%>