asp formmail auto responder - html

I'm very bad at coding
i have a asp formmail for subscribe email. I do get emails but I want to send a autoresponse saying "Thank you for subscription". Also the same for my contact page formmail.
Below is my current code
can you tell me how do I go about the same.
<%
dim sEmailContent
sEmailContent = sEmailContent & "Subscribe : " & Request.Form("subscribe") & vbCrLf
Response.Write(sEmailContent)
'call send_email("here#herringboneandsui.com",sEmailContent)
call send_email("here#herringboneandsui.com",sEmailContent)
function send_email(sToEmail,sEmailBody)
on error resume next
Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message")
'Configuration for remote SMTP server
'Network Send
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name of SMTP server
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="relay-hosting.secureserver.net"
'SMTP port
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'MaxESP SMTP servers require authentication
'Basic Authentication
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'SMTP username as configured in the control panel
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="bla#bla.com"
'SMTP user password as configured in the control panel
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="blabla"
ObjSendMail.Configuration.Fields.Update
'Configuration for email message
'Email To address
'ObjSendMail.To = "bla#gmail.com"
'ObjSendMail.To = "bla#mac.com"
ObjSendMail.To = sToEmail
'Email Subject
ObjSendMail.Subject = "Newsletter Subscription"
'Email From address
ObjSendMail.From = "bla#herringboneandsui.com"
'Email Body
ObjSendMail.TextBody = sEmailBody
ObjSendMail.Send
Set ObjSendMail = Nothing
response.Redirect("thank-you.html")
if err.number <> 0 then
Response.Write(err.Description)
end if
on error goto 0
end function
%>

move your function function send_email(sToEmail,sEmailBody) into separate file, let's say into "Emails.asp".
in contact page and in subscribe asp pages add following line to include your "Email.asp"
<!-- #include file="Emails.asp" -->
then call send_email as before

Related

VBA Cancel send email sent by Gmail

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

Sending an e-mail via VBA with Outlook Exchange

So for many years I've been using CDO to send e-mails via POP and have had no issues. However, we are going to be upgrading to an Outlook Exchange e-mail server and POP is no longer available, it also requires TLS which I've read isn't supported by CDO.
This is what I have been doing:
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "my smtpserver"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "email#email.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Update
End With
Set objEmail = CreateObject("CDO.Message")
Set objEmail.Configuration = cdoConfig
This has always worked in the past. I tried updating the smtp server to smtp.office365.com and the port to 587 but I get the following error:
The server rejected the sender address. The server response was: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [MWHPR08CA0030.namprd08.prod.outlook.com]
I'm currently using Access 2003, we will be upgrading to 2015 soon, but for now I need a solution that works in 2003.
Thanks.

ms access module to add attachment from button

I am having the following code in a module, which it is send email with attachment to user.
Public Sub EmailToUser()
Dim mail As Object ' CDO.MESSAGE
Dim config As Object ' CDO.Configuration
Set mail = CreateObject("CDO.Message")
Set config = CreateObject("CDO.Configuration")
config.Fields(cdoSendUsingMethod).Value = cdoSendUsingPort
config.Fields(cdoSMTPServer).Value = "my smtp server"
config.Fields(cdoSMTPServerPort).Value = 465
config.Fields(cdoSMTPConnectionTimeout).Value = 10
config.Fields(cdoSMTPUseSSL).Value = "true"
config.Fields(cdoSMTPAuthenticate).Value = cdoBasic
config.Fields(cdoSendUserName).Value = "e=mail"
config.Fields(cdoSendPassword).Value = "password"
config.Fields.Update
Set mail.Configuration = config
With mail
.To = "e-mail"
.From = "e-mail"
.Subject = "subject"
.AddAttachment strPathReport & FileName '<== My question.
.Send
End With
Set config = Nothing
Set mail = Nothing
End Sub
I have a form with 8buttons and each button is send an email with an attachment.
Now, I have in my module 8 times the same code with different attachment.
Is it possible to have only one time the above code and from the button to add the attachment?
Thank you.
Basically you want to add parameters to the procedure. And then pass in the e-mail address, etc. as arguments.
This question should give you some ideas on how to do that: multiple argument subs vba

Insert Dynamic Table into email

The below script generates a text list and inserts it into an email and sends to specific people. It works fine as plain text. What I am trying to accomplish is to create a dynamic html table and insert into the body of the email. I have tried to add html tags around the TextBody for the .HTMLBody property, but no email came out. I changed the template files to .html files and created html tables in there, but the email had the code as plain text.
Here is a sample of the working output:
AREA: Line 2
SPID: 308582 Name: LINE 2 ROBERTS NO 2 COOLING LINE East
Expectation: BiMonthly
Projected: +2mos Last Sampled Approved Date: 2013-06-10
I would like to have all the text before the colons to be the headers and then the results listed below the headers.
Option Explicit
Dim mConnectionString, objFSO, vEmailTemplateFile, vEmailTemplateSPID
Dim blnDebugMode, DebugLogLevel
Dim oConn 'ADO connection
Dim vLogDir,LogFilePrefix,gstrmsg
Dim adminEmail, EmailSubject, smtpServer
mConnectionString = "Provider=SQLOLEDB;Server=;Initial Catalog;Integrated Security=;"
vEmailTemplateFile = "C:\EMAILScripts\SampleReminderTemplate.txt"
vEmailTemplateSPID = "C:\EMAILScripts\SampleReminderSPIDTemplate.txt"
'Read in SPID template
sSPIDTemplate = ""
Set objFileStreamIn = objFSO.OpenTextFile(vEmailTemplateSPID, ForReading)
Do Until objFileStreamIn.AtEndOfStream
sSPIDTemplate = sSPIDTemplate & objFileStreamIn.ReadLine & vbCrLf
Loop
objFileStreamIn.Close
'Read in email template and create email by replacing tokens and then send
sEmailMsg = ""
Set objFileStreamIn = objFSO.OpenTextFile(vEmailTemplateFile, ForReading)
Do Until objFileStreamIn.AtEndOfStream
sEmailMsg = sEmailMsg & objFileStreamIn.ReadLine & vbCrLf
Loop
objFileStreamIn.Close
sEmailMsg = Replace(sEmailMsg,"{name}",sName)
sEmailMsg = Replace(sEmailMsg,"{body}",sBody)
'LogMessage "sEmailMsg: " & sEmailMsg, False, LogDebug
If blnDebugMode Then
sEmail = adminEmail '<< In debug mode send ALL emails to the admin address set above
End If
If blnEmail Then
If SendMailByCDO(adminEmail, EmailSubject, FullErrorMsg, "", "", smtpServer, adminEmail) <> 0 Then
LogMessage "Could Not send email: " & ErrMsg, False, LogError
If errNumber <> Err.Number Then
Err.Clear
End If
End If
End If
'***************************************
'* Sends an email To aTo email address, with Subject And TextBody.
'* The email is In text format.
'* Lets you specify BCC adresses, Attachments, smtp server And Sender email address
'***************************************
Function SendMailByCDO(aTo, Subject, TextBody, BCC, Files, smtp, aFrom )
'On Error Resume Next
Dim Message 'As New CDO.Message '(New - For VBA)
Set Message = CreateObject("CDO.Message")
With Message.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = aFrom
'SMTP settings - without authentication, using standard port 25 on host smtp
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtp
'SMTP Authentication
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous
'**** You can also specify authentication properties for the smtp session using
'**** smtpauthenticate and sendusername + sendpassword:
'* .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
'* .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "info#mycompany.to"
'* .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
'* .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True/False
'****
.Update
End With
'Set other message fields.
With Message
.From = aFrom
.To = aTo
.Subject = Subject
'Set TextBody property If you want To send the email As plain text
'.TextBody = TextBody
'* Set HTMLBody property If you want To send the email As an HTML formatted
.HTMLBody = TextBody
'Blind copy And attachments are optional.
If Len(BCC)>0 Then .BCC = BCC
If Len(Files)>0 Then .AddAttachment Files
'Send the email
.Send
End With
IF blnDebugMode and Err.Number <> 0 then
Wscript.Echo "SendMailByCDO err: " & err.description
End IF
'Returns zero If successful. Error code otherwise
SendMailByCDO = Err.Number
End Function
EDIT1: removed extra code to only show email functions.
I created an html file called SampleReminderSPIDTemplateTable.html to replace SampleReminderSPIDTemplate.txt and in that file is the following:
<html xmlns="http://www.w3.org/1999/xhtml">
<table style="width:100%">
<tr>
<td>{AREANAME}</td>
<td>{SPID}</td>
<td>{SPIDNAME}</td>
<td>{LASTSAMPLEAPPROVEDDATE}</td>
<td>{EXPECTATION}</td>
<td>{PROJECTED}</td>
</tr>
</table>
</html>
I also try this to .HTMLBody property, but no emails went out.
.HTMLBody = "<html><body><pre>" & TextBody & "</pre></body></html>"

MS Access send email (not from outlook or user's email)

I know this question has been asked a few times in various context, but I have not found a clear answer. I have email implemented for an access application using outlook, but I'd like to move away from this. One of the purposes of the email is to email a user his/or password if he forgot it. They can select their username for the login screen, and if they click 'forgot password' and email is sent containing their login information (to the email address associated with the user name).
The problem with this is that the email function as is sends an email with outlook from the user's machine. So, users would be able to 'forgot password' other usernames and view their own outlook outbox(sent items) to see the sensitive information.
Is there a way to e-mail like php's mail function, sending mail from the server? I would like the emails to be sent from the same email address i.e(support#company.com), instead of from the user's outlook address after a security prompt. If this is not possible, I am open to the idea of any other workarounds.
I will also add that installing any software that would have to be installed on every potential user's machine is not feasible.
Is this possible?
Windows includes an object called Collaborative Data Objects or CDO. This object allows you to send emails using any SMTP server assuming that other prerequisites are met (firewall open, ISP not blocking ports, account is configured on the SMTP server, SMTP server allows relaying, etc).
Most of the examples I've found use late binding, which is preferred. In my testing on XP it appeared that the correct library reference, if you prefer to use early binding, is "Microsoft CDO for Windows 2000 Library".
It's important to know that any time you send email you will have to send it through (or out of) some kind of email server. This means you will have to authenticate with that email server and also usually means that you need to send the email out using a "From" email address that exists on that very email server.
Here's some code using late binding:
Const cdoSendUsingPickup = 1
Const cdoSendUsingPort = 2
Const cdoAnonymous = 0
' Use basic (clear-text) authentication.
Const cdoBasic = 1
' Use NTLM authentication
Const cdoNTLM = 2 'NTLM
Public Sub SendEmail()
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
' send one copy with SMTP server (with autentication)
schema = "http://schemas.microsoft.com/cdo/configuration/"
flds.Item(schema & "sendusing") = cdoSendUsingPort
flds.Item(schema & "smtpserver") = "mail.myserver.com"
flds.Item(schema & "smtpserverport") = 25
flds.Item(schema & "smtpauthenticate") = cdoBasic
flds.Item(schema & "sendusername") = "email#email.com"
flds.Item(schema & "sendpassword") = "password"
flds.Item(schema & "smtpusessl") = False
flds.Update
With imsg
.To = "email#email.com"
.From = "email#email.com"
.Subject = "Test Send"
.HTMLBody = "Test"
'.Sender = "Sender"
'.Organization = "My Company"
'.ReplyTo = "address#mycompany.com"
Set .Configuration = iconf
.Send
End With
Set iconf = Nothing
Set imsg = Nothing
Set flds = Nothing
End Sub
This works for me in MS Access 2010 / Windows 7
sMailServer = "myISPsmtp" 'Not just any old smtp
sMailFromAddress = "me"
sMailToAddress = "me"
Set ObjMessage = CreateObject("CDO.Message")
sToAddress = sMailToAddress
sSubject = "Subject"
sBody = "MailBody"
ObjMessage.Subject = sSubject
ObjMessage.From = sMailFromAddress
ObjMessage.To = sToAddress
'ObjMessage.cc = sCCAddress
ObjMessage.TextBody = sBody
'ObjMessage.AddAttachment sMailAttachment
ObjMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
ObjMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sMailServer
ObjMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
ObjMessage.Configuration.Fields.Update
ObjMessage.send
More info: http://msdn.microsoft.com/en-us/library/ms526318(v=exchg.10).aspx
I cannot add this to the comments because I do not have enough reputation, so please don't axe me.
"Seems like this method lets you spoof about anything on my server. Just noticed that there's an addAttachment method. Could that work with just a relative path to say, an excel sheet? "
It works for me (Access 2010, Exchange 2010):
.AddAttachment ("URL HERE")
https://msdn.microsoft.com/en-us/library/ms526453(v=exchg.10).aspx
https://msdn.microsoft.com/en-us/library/ms526983(v=exchg.10).aspx
The following MS-Access VBA code works for smtp.office365.com. You DO indicate smtpusessl=true, but you do NOT specify the port, otherwise you get error 5.7.57.
Sub SMPTTest2()
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "name#myaddress.com"
emailObj.To = "name#youraddress.com"
emailObj.Subject = "Test CDO"
emailObj.TextBody = "Test CDO"
'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"
'Exclude the following line
'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#myaddress.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword"
emailConfig.Fields.Update
emailObj.Send
If Err.Number = 0 Then MsgBox "Done"
End Sub
At my company I used a other solution. I have created a C# Class Library with COM classes / objects. COM classes can be implemented in your Access application and this way you can use all the advantages of C# (Mailing for example) and still use it (calling it) in Access.
The only disadvantage is that you have to register your Class Library (DLL) at all the computers who use your access application. I have done that with a simple power-shell script which executes at the start of the Access application.
A good start for A COM based library is here: https://www.codeproject.com/Articles/7859/Building-COM-Objects-in-C
If you would like some more information about it then I am always happy to help you.