Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automatically send email after a set of time 1

Status
Not open for further replies.

davyre

Programmer
Oct 3, 2012
197
AU
Hi,
I dont know if it is possible but can I program a code to send an email automatically (without using Outlook) when an order status has been changed to "Ready"?
So in the Order form, when the Status textbox value="Ready", it will start countdown on for example 5 days after that, and it will automatically send a simple email.
Currently I have this code
Code:
Private Sub Sendmaila_Click()

Dim Subject As String
Dim MailTo As String
Dim MailFrom As String
Dim BodyText As String
Dim Result As Boolean
Dim ServerName As String
Subject = "Hello World"
MailTo = "****@yahoo.com"
MailFrom = "****@gmail.com"
BodyText = "This is the body of the email message"
ServerName = "smtp.gmail.com"
Result = SendEMail( _
    Subject:=Subject, _
    FromAddress:=MailFrom, _
    ToAddress:=MailTo, _
    MailBody:=BodyText, _
    SMTP_Server:=ServerName, _
    BodyFileName:=vbNullString)

End Sub
**note: I already copied a code from to a module which has function SendEMail()


This code is triggered with a button click, but when I click a button, nothing is happened (i.e no email was received to the recipient).
So in conclusion, I have two questions:
1. How to send this simple email without using Outlook ( I dont want any warnings/more input, just automatically send the email)
2. How to trigger sending the email after a set of time (5 days)
 
UPDATE:

I changed my code to this
Code:
Private Sub Command39_Click()
Dim cdoConfig
Dim msgOne

Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
    .Item(cdoSendUsingMethod) = cdoSendUsingPort
    .Item(cdoSMTPServerPort) = 25 ' (your port number) usually is 25
    .Item(cdoSMTPServer) = "smtp.gmail.com" ' your SMTP server goes here
    '.Item(cdoSendUserName) = "My Username"
    '.Item(cdoSendPassword) = "myPassword"
    .Update
End With

Set msgOne = CreateObject("CDO.Message")
Set msgOne.Configuration = cdoConfig
msgOne.To = "*****@Hotmail.com"
msgOne.From = "*****@Gmail.com"
msgOne.Subject = "Test CDO"
msgOne.TextBody = "It works just fine."
msgOne.Send
End Sub

and it worked perfectly.
Now to the second question which triggers the email to be sent once in 5 days after the status is changed to "Ready". Any help? Thanks
 
An idea...what if you have a separate table with the values you need to pass to the email code and the ready date. When the records status is changed to ready, append it to this table. Then you could have a query or code that selects all the records where the ready date is > 4, run the email process, then delete the records. That way, if for some reason you are not able to run the process on the 5th day, the records will be ready to run in the future and once run will be gone, so won't have to worry that they would be emailed again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top