im intresting in sending email via asp page.
i looked after it on the internet and i found something.
<%
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
.Item(sch & "smtpserver") = "smtp.gmail.com"
.update
End With
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.From = Request.Form("From")
.To = Request.Form("To")
.Subject = Request.Form("Subject")
.TextBody = Request.Form("Body")
.Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing
%>
but its not sending me the email its saying something like "the traffic couldn't connect to the server" what should i change in the code??
Thank you very much.
i think you have to set username and password for the smtp server and set the "smtpauthenticate" property to true:
.item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.item("http://schemas.microsoft.com/cdo/configuration/sendusername") = usrName
.item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = pwd
Related
I know that Google Gmail was a functionality to cancel the sent email within 30 seconds.
As I'm using this code to send emails from an access database, and via gmail, I would like to know if there's a way to use that functionality to prevent sending an email for mistake?
Sub SendEmail_Click()
Dim NewMail As CDO.Message
Set NewMail = New CDO.Message
'Enable SSL Authentication
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
'Make SMTP authentication Enabled=true (1)
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'Set the SMTP server and port Details
'To get these details you can get on Settings Page of your Gmail Account
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Set your credentials of your Gmail Account
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "mysite#gmail.com"
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword7"
'Update the configuration fields
NewMail.Configuration.Fields.Update
'Set All Email Properties
With NewMail
Dim strPath As String
strPath = ".mysite/wp-content/uploads/2017/07/myimage.png"
.subject = "this is the subject"
.From = "<mail#mysite.com>"
.To = Me.EMAIL
'.CC = ""
'.BCC = ""
.HTMLBody = "This is my message body"
.AddAttachment "https://mysite/temp/contacts.vcf"
End With
NewMail.Send
MsgBox ("This email was sent!")
'Set the NewMail Variable to Nothing
Set NewMail = Nothing
End Sub
i am requesting a problem about forgot password .
if user forgot his/her password how can i return his/her same password in email address? My problem would be the SQL database password is encrypted how am I suppose to retrieve the same password instead encrypted.
i did like this:
<!--
METADATA
TYPE="typelib"
UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
NAME="CDO for Windows 2000 Library"
-->
<%
DIM strEmail
strEmail = Request.Form("email")
IF strEmail <> "" THEN
%>
<%
DIM objDB, rs, rssql
Set objDB = Server.CreateObject("ADODB.Connection")
objDB.Open "Provider=MSDASQL.1;Password=langas;Persist Security Info=True;User ID=mmsg;Data Source=mmsg_web"
rssql = "SELECT email_addr, medacist_password FROM medacist_user WHERE email_addr = '" & strEmail & "'"
Set rs = objDB.Execute(rssql)
IF rs.EOF THEN
Response.Write "That email address was not found in our database. Please click Back on your browser and enter the email address you registered with."
ELSE
DIM strPassword
set strPassword = rs("medacist_password")
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "10.1.1.186" 'Ongoing sever SMTP required \\'
'' .Item(cdoSMTPAuthenticate) = 1'
'' .Item(cdoSendUsername) ="<enter_username>"
' ' .Item(cdoSendPassword) ="<enter_password>"''
.Update
End With
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.From = "clu#medacist.com"
.To = strEmail
.Subject = "Forgotten Password"
.HTMLBody = "Here is your password: " & strPassword
.Importance = 1
.Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing
Response.Write "Your password has been sent to your email address."
END IF
ELSE
Response.Write "Please click Back on your browser and enter the email address you registered with."
END IF
%>
<!-- "Please click below link to reset your password: <br> <a href='https://www.medacist.com/login/test_globals.asp'>Click this link to reset your password</a>" -->
You aren't supposed to retrieve the password.
You should generate a long, pesudo-random token. Store it for a short time (e.g. 24 hours). Send it to the user (normally embedded in a URL). When the user follows the link in the email, they should get a page allowing them to set a new password (and you can use the token in the URL to identify which user's password is being changed).
Is there any way to send a mail in HTML format (and if possible with attachments) when your default mail client isn't Outlook?
Many thanks for any solution.
You should be able to use CDO (Collaboration Data Objects). The code will look something like this:
Option Compare Database
Option Explicit
Sub cdoHtmlTest()
Const urlPrefix = "http://schemas.microsoft.com/cdo/configuration/"
Dim msg As Object ' CDO.Message
Set msg = CreateObject("CDO.Message") ' New CDO.Message
With msg.Configuration.Fields
.Item(urlPrefix & "sendusing") = 2 ' cdoSendUsingPort
.Item(urlPrefix & "smtpserver") = "smtp.example.com"
.Item(urlPrefix & "smtpserverport") = 25
.Item(urlPrefix & "smtpauthenticate") = 1 ' cdoBasic
.Item(urlPrefix & "sendusername") = "mySmtpUserName"
.Item(urlPrefix & "sendpassword") = "mySmtpPassword"
.Item(urlPrefix & "smtpusessl") = False
.Update ' remember to do this step!
End With
With msg
.To = "gord#example.com"
.From = "gord#example.com"
.Subject = "HTML message test"
.HTMLBody = "This is a <strong>TEST</strong>."
.Send
End With
Set msg = Nothing
End Sub
For more examples (including how to send attachments), look here.
I'm trying to send email using VBA code, the function is working and the email is sent, but the problem is when function end 'Run-time error 438 object doesn't support this property or method' appears
here is the code:
Public Function SendEmail(ItemName As String, Total_Qnty As Integer)
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
' send one copy with Google SMTP server (with autentication)
schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing") = 2
Flds.Item(schema & "smtpserver") = "smtp.gmail.com"
Flds.Item(schema & "smtpserverport") = 465
Flds.Item(schema & "smtpauthenticate") = 1
Flds.Item(schema & "sendusername") = "example#gmail.com"
Flds.Item(schema & "sendpassword") = "*****"
Flds.Item(schema & "smtpusessl") = 1
Flds.Update
With iMsg
.To = "example#hotmail.com"
.From = "example#gmail.com"
.Subject = "Mail from gmail"
.HTMLBody = "The Stock Safty Level of Item: " & ItemName & " is DOWN, The total quantity you have is: " & Total_Qnty & "!!"
Set .Configuration = iConf
.Send
End With
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
End Function
Pleased any ideas .. Thank you
Most probably it's a binary compatibility issue between components.
Microsoft says "Run Time Error 438 - Object Doesn't Support this Property or Method:
The most common cause of error 438 is not maintaining binary compatibility between successive versions of your components. Each COM interface has an associated GUID that is called an interface ID (IID). Each coclass has an associated GUID that is called class ID (CLSID). When you compile an ActiveX component in Visual Basic, the CLSIDs and IIDs are compiled into the component's type library."
In this link it's explained how to solve a similar problem:
http://www.vbforums.com/showthread.php?460591-RESOLVED-Runtime-error-438-Object-doesn-t-support-this-property-or-method
Reverse the order of these:
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
Flds is a member of iConf which, currently, you have already disposed of.
I have some VBScript to send an email. But when I try to send text which is Unicode, the result is something that is unreadable. I tried something like .Charset="UTf-8" but it's hopeless. My VBScript code is below; the emailbody.txt file contains something like this "hệ điều hành khởi động !"
Option Explicit
Call Email
Function Email
Dim iMsg, iConf, Flds, schema
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") = 2
Flds.Item(schema & "smtpserver") = "smtp.gmail.com"
Flds.Item(schema & "smtpserverport") = 465
Flds.Item(schema & "smtpauthenticate") = 1
Flds.Item(schema & "sendusername") = ""
Flds.Item(schema & "sendpassword") = ""
Flds.Item(schema & "smtpusessl") = 1
Flds.Update
'These constants are defined to make the code more readable
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f, BodyText, HeadText
Set fso = CreateObject("Scripting.FileSystemObject")
'Open the file for reading
Set f = fso.OpenTextFile("emailbody.txt", ForReading) 'edit path if required
'The ReadAll method reads the entire file into the variable BodyText
BodyText = f.ReadAll
'Close the file
f.Close
Set f = Nothing
Set fso = Nothing
With iMsg
.To = ""
.From = ""
.Sender = ""
.Subject = ""
.HTMLBody = BodyText
Set .Configuration = iConf
.Send
End With
set iMsg = nothing
set iConf = nothing
set Flds = nothing
End Function
Read the email body using Adodb.Stream object. Because FSO does not support reading utf-8 encoded files.
Fill the BodyText variable like that:
Dim adoStream
Set adoStream = CreateObject("Adodb.Stream")
adoStream.Open
adoStream.Charset = "UTF-8"
adoStream.LoadFromFile "emailbody.txt"
'********** !! ***************
BodyText = adoStream.ReadText(-1)
'********** !! ***************
adoStream.Close
Set adoStream = Nothing
And, set
iMsg.BodyPart.Charset = "utf-8"