Here is the code that I have: The email is being sent and received however the message body is not. Please help! - <%
-
dim sql, rs, rs1, reportID, mail, body
-
dim jobSite, jobSiteNum, reportDate, supervisor, weather, temperature, comment, problem
-
dim emailTo, emailToArr, emailSubject, temp, header
-
set conn = Server.CreateObject("ADODB.Connection")
-
conn.Open connString
-
set rs = Server.CreateObject("ADODB.Recordset")
-
set rs1 = Server.CreateObject("ADODB.Recordset")
-
reportID = Request.Form("reportID")
-
if reportID <> "" Then
-
sql = "SELECT * FROM TblReport r, TblJobSite js, TblUser u " & _
-
"WHERE r.JobSiteID = js.JobSiteID AND r.SupervisorID = u.UserID " & _
-
"AND ReportID = " & reportID
-
rs.Open sql, conn
-
emailTo = Request.Form("txtEmailTo")
-
emailToArr = Split(emailTo,";")
-
emailSubject = Request.Form("txtEmailSubject")
-
set mail = Server.CreateObject("CDO.Message")
-
mail.From = getSetting("pEmailFrom")
-
mail.To = emailTo
-
mail.Subject = emailSubject
-
body = "<html><head><title>Report</title>"
-
body = body & "<style type='text/css'>body, td { font-family:Verdana; font-size:11px; } </style>"
-
body = body & "</head><body>"
...
Here is another example of code that I wrote that was unsuccessful: - <%
-
dim sql, rs, rs1, reportID, mail, body
-
dim jobSite, jobSiteNum, reportDate, supervisor, weather, temperature, comment, problem
-
dim emailTo, emailToArr, emailSubject, temp, header
-
-
set conn = Server.CreateObject("ADODB.Connection")
-
conn.Open connString
-
set rs = Server.CreateObject("ADODB.Recordset")
-
set rs1 = Server.CreateObject("ADODB.Recordset")
-
reportID = Request.Form("reportID")
-
if reportID <> "" Then
-
sql = "SELECT * FROM TblReport r, TblJobSite js, TblUser u " & _
-
"WHERE r.JobSiteID = js.JobSiteID AND r.SupervisorID = u.UserID " & _
-
"AND ReportID = " & reportID
-
rs.Open sql, conn
-
if NOT rs.EOF Then
-
jobSite = rs.Fields("JobSiteName")
-
jobSiteNum = rs.Fields("JobSiteNum")
-
reportDate = rs.Fields("ReportDate")
-
supervisor = rs.Fields("FirstName") & " " & rs.Fields("LastName")
-
if not isnull(rs.Fields("WeatherID")) Then
-
sql = "SELECT * FROM TblWeather WHERE WeatherID = " & rs.Fields("WeatherID")
-
rs1.Open sql, conn
-
if not rs1.EOF Then
-
weather = rs1.Fields("WeatherName")
-
end If
-
rs1.Close
-
end If
-
temperature = rs.Fields("Temperature")
-
comment = rs.Fields("Comment")
-
problem = rs.Fields("Problem")
-
end if
-
-
rs.Close
-
-
emailTo = Request.Form("txtEmailTo")
-
emailToArr = Split(emailTo,";")
-
-
'set mail = Server.CreateObject("Persits.MailSender")
-
set objMessage = createobject("cdo.message")
-
set objConfig = createobject("cdo.configuration")
-
Set Flds = objConfig.Fields
-
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
-
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mail.mydomain.com"
-
' ' Passing SMTP authentication
-
Flds.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
-
Flds.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="postmaster@mydomain.com"
-
Flds.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="MyPassword"
-
Flds.update
-
Set objMessage.Configuration = objConfig
-
Set Flds = objConfig.Fields
-
objMessage.To = emailTo
-
objMessage.From = getSetting("pEmailFrom")
-
objMessage.Subject = Request.Form("txtEmailSubject")
-
objMessage.fields.update
-
objMessage.HTMLBody = body
-
-
body = body & "<html><head><title>Report</title>"
-
body = body & "<style type='text/css'>body, td { font-family:Verdana; font-size:11px; } </style>"
-
body = body & "</head><body>"
-
...
-
-
body = body & "</body></html>"
-
-
'mail.Body = body
-
'mail.AddEmbeddedImage Server.MapPath("/Images/Calendar Email Logo.jpg"), "Logo" ' Embed logo in email body
-
'mail.IsHTML = true
-
-
'Attach pictures to email
-
dim path
-
path = Server.MapPath("Pictures")
-
-
sql = "SELECT * FROM TblReportPicture WHERE ReportID = " & reportID
-
rs.Open sql, conn
-
if NOT rs.EOF then
-
do until rs.EOF
-
mail.AddAttachment path & "/" & rs.Fields("Filename")
-
rs.MoveNext
-
loop
-
end if
-
rs.Close
-
-
On Error Resume Next
-
objMessage.Send
-
set mail = nothing
13 9669
Are you sure your web server has access to the e-mail servers?
They are both within the same hosting company so I would assume so.
That doesn't mean the proxy account has access to it. You should ask them if it does, and if so, what server settings to use.
Thx. I will get back to you as soon as I get a response from their Tech.
Here is the message that was given to me:
"Yes. The web server has access to the email server. Remember if you are able to manually type the body, instead of passing the variable through, and the email comes through means that the application is able to connect to the mail server and relay it out. The problem is the form page, passing the body from the form page to the actual CDO page to set out the email. That's where it seems to be breaking down."
Would it help if I posted the code for the prior page?
You need to populate the body variable (body = "...") Before you assign it to the email body (objmessage.htmlbody = body). Asp doesn't usually use references, instead it passes current content. Does this make sense?
Jared
No I'm sorry it does not.
How then would I build an html coded email that I can send?
This is the full code that I have for the page: - <%
-
dim sql, rs, rs1, reportID, mail, body
-
dim jobSite, jobSiteNum, reportDate, supervisor, weather, temperature, comment, problem
-
dim emailTo, emailToArr, emailSubject, temp, header
-
-
set conn = Server.CreateObject("ADODB.Connection")
-
conn.Open connString
-
set rs = Server.CreateObject("ADODB.Recordset")
-
set rs1 = Server.CreateObject("ADODB.Recordset")
-
reportID = Request.Form("reportID")
-
if reportID <> "" Then
-
sql = "SELECT * FROM TblReport r, TblJobSite js, TblUser u " & _
-
"WHERE r.JobSiteID = js.JobSiteID AND r.SupervisorID = u.UserID " & _
-
"AND ReportID = " & reportID
-
rs.Open sql, conn
-
if NOT rs.EOF Then
-
jobSite = rs.Fields("JobSiteName")
-
jobSiteNum = rs.Fields("JobSiteNum")
-
reportDate = rs.Fields("ReportDate")
-
supervisor = rs.Fields("FirstName") & " " & rs.Fields("LastName")
-
if not isnull(rs.Fields("WeatherID")) Then
-
sql = "SELECT * FROM TblWeather WHERE WeatherID = " & rs.Fields("WeatherID")
-
rs1.Open sql, conn
-
if not rs1.EOF Then
-
weather = rs1.Fields("WeatherName")
-
end If
-
rs1.Close
-
end If
-
temperature = rs.Fields("Temperature")
-
comment = rs.Fields("Comment")
-
problem = rs.Fields("Problem")
-
end if
-
-
rs.Close
-
-
emailTo = Request.Form("txtEmailTo")
-
emailToArr = Split(emailTo,";")
-
-
set objMessage = createobject("cdo.message")
-
set objConfig = createobject("cdo.configuration")
-
Set Flds = objConfig.Fields
-
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
-
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mail.mydomain.com"
-
-
' ' Passing SMTP authentication
-
Flds.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
-
Flds.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="postmaster@mydomain.com"
-
Flds.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="XXXXX"
-
Flds.update
-
-
Set objMessage.Configuration = objConfig
-
Set Flds = objConfig.Fields
-
objMessage.To = emailTo
-
objMessage.From = getSetting("pEmailFrom")
-
objMessage.Subject = Request.Form("txtEmailSubject")
-
objMessage.fields.update
-
objMessage.HTMLBody = body
-
-
body = body & "<html><head><title>Report</title>"
-
body = body & "<style type='text/css'>body, td { font-family:Verdana; font-size:11px; } </style>"
-
body = body & "</head><body>"
-
body = body & "<table border='0' cellspacing='0' cellpadding='3'>"
-
-
'Report header
-
header = getSetting("pCompanyAddress") & ", " & getSetting("pCompanyCity") & ", " & getSetting("pCompanyProvince") & " " & getSetting("pCompanyPostalCode") & _
-
"<br>Phone: " & getSetting("pCompanyPhone") & " Fax: " & getSetting("pCompanyFax") & "<br><br>" & _
-
"<h4 align='center'>Project Daily Report</h4>"
-
body = body & "<tr><td colspan='2' align='center'><img src='http://www.mydomain.com/Images/Calendar Email Logo.jpg' border='0' /><br>" & header & "</td></tr>"
-
-
body = body & "<tr><td width='120'><b>Report #:</b></td><td><b>" & reportID & "</b></td></tr>"
-
body = body & "<tr><td><b>Job Site:</b></td><td><b>" & jobSite & "</b></td></tr>"
-
body = body & "<tr><td><b>Job Site #:</b></td><td><b>" & jobSiteNum & "</b></td></tr>"
-
body = body & "<tr><td><b>Date:</b></td><td><b>" & FormatDateTime(reportDate,1) & "</b></td></tr>"
-
body = body & "<tr><td><b>Site Supervisor:</b></td><td><b>" & supervisor & "</b></td></tr>"
-
body = body & "<tr><td><b>Weather:</b></td><td>" & weather & "</td></tr>"
-
body = body & "<tr><td><b>Temperature:</b></td><td>" & temperature & "</td></tr></table>"
-
-
'Trades on site
-
Dim i
-
sql = "SELECT * FROM TblTrade t, TblReportTrade rt " & _
-
"WHERE t.TradeID = rt.TradeID AND rt.ReportID = " & reportID & _
-
" ORDER BY TradeName"
-
rs.Open sql, conn
-
if NOT rs.EOF Then
-
i = 0
-
body = body & "<table border='0' cellspacing='0' cellpadding='3'>"
-
body = body & "<tr><td><b>Trades on site:</b></td><td>Number of Men</td><td> </td><td><b>Trades on site:</b></td><td>Number of Men</td></tr>"
-
do until rs.EOF
-
If(i Mod 2 = 0) Then
-
body = body & "<tr><td>" & rs.Fields("TradeName") & "</td><td>" & rs.Fields("MenNumber") & "</td><td> </td>"
-
Else
-
body = body & "<td>" & rs.Fields("TradeName") & "</td><td>" & rs.Fields("MenNumber") & "</td></tr>"
-
End If
-
i = i + 1
-
rs.MoveNext
-
loop
-
end If
-
If (i Mod 2 = 1) Then
-
body = body & "<td> </td><td> </td>></tr>"
-
End If
-
body = body & "</table>"
-
rs.Close
-
-
'Comments and Problems
-
body = body & "<table border='0' cellspacing='0' cellpadding='3'>"
-
body = body & "<tr><td valign='top'><b>Comments:</b></td><td>" & comment & "</td></tr>"
-
body = body & "<tr><td valign='top'><b>Problems:</b></td><td>" & problem & "</td></tr>"
-
body = body & "</table>"
-
-
'Accidents
-
sql = "SELECT * FROM TblReportAccident WHERE ReportID = " & reportID
-
rs.Open sql, conn
-
If Not rs.EOF Then
-
body = body & "<table border='0' cellspacing='0' cellpadding='3'>"
-
body = body & "<tr><td width='120'><b>Accident:</b></td><td colspan='3'>" & rs.Fields("AccidentOn") & "</td></tr>"
-
body = body & "<tr><td> </td><td colspan='3'>" & rs.Fields("Description") & "</td></tr>"
-
-
'Accident WCB
-
sql = "SELECT * FROM TblReportAccident ra, TblWCBDoc w WHERE ra.ReportAccidentID = w.ReportAccidentID AND ra.ReportID = " & reportID
-
rs1.Open sql, conn
-
body = body & "<tr><td> </td><td><b>WCB File Name</b></td><td><b>Date Uploaded</b></td><td> </td></tr>"
-
If Not rs1.EOF Then
-
Do Until rs1.EOF
-
body = body & "<tr><td> </td><td>" & rs1("FileName") & "</td><td>" & rs1("DateUploaded") & "</td><td><a href='http://www.mydomain.com/Report/WCB/" & rs1("FileName") & "' target='_blank'>View</a></td></tr>"
-
rs1.MoveNext
-
Loop
-
Else
-
body = body & "<tr><td> </td><td>-</td><td>-</td><td> </td></tr>"
-
End If
-
rs1.Close
-
-
sql = "SELECT * FROM TblReportAccident ra, TblWCBPicture w WHERE ra.ReportAccidentID = w.ReportAccidentID AND ra.ReportID = " & reportID
-
rs1.Open sql, conn
-
body = body & "<tr><td> </td><td><b>Picture File Name</b></td><td><b>Description</b></td><td> </td></tr>"
-
If Not rs1.EOF Then
-
Do Until rs1.EOF
-
body = body & "<tr><td> </td><td>" & rs1("FileName") & "</td><td>" & rs1("Description") & "</td><td><a href='http://www.mydomain.com/Report/WCB/" & rs1("FileName") & "' target='_blank'>View</a></td></tr>"
-
rs1.MoveNext
-
Loop
-
Else
-
body = body & "<tr><td> </td><td>-</td><td>-</td><td> </td></tr>"
-
End If
-
rs1.Close
-
body = body & "</table>"
-
-
End If
-
rs.Close
-
-
-
'Equipment
-
Dim j
-
sql = "SELECT * FROM TblEquipment e, TblReportEquipment re " & _
-
"WHERE e.EquipmentID = re.EquipmentID AND re.ReportID = " & reportID & _
-
" ORDER BY EquipmentName"
-
rs.Open sql, conn
-
if NOT rs.EOF Then
-
j = 0
-
body = body & "<table border='0' cellspacing='0' cellpadding='3'>"
-
body = body & "<tr><td><b>Equipment:</b></td><td>Number</td><td> </td><td><b>Equipment:</b></td><td>Number</td></tr>"
-
do until rs.EOF
-
If(j Mod 2 = 0) Then
-
body = body & "<tr><td>" & rs.Fields("EquipmentName") & "</td><td>" & rs.Fields("Number") & "</td><td> </td>"
-
Else
-
body = body & "<td>" & rs.Fields("EquipmentName") & "</td><td>" & rs.Fields("Number") & "</td></tr>"
-
End If
-
j = j + 1
-
rs.MoveNext
-
loop
-
end if
-
If (j Mod 2 = 1) Then
-
body = body & "<td> </td><td> </td>></tr>"
-
End If
-
body = body & "</table>"
-
rs.Close
-
-
'Site Personnel
-
sql = "SELECT * FROM TblUser u, TblReportUser ru " & _
-
"WHERE u.UserID = ru.UserID AND ru.ReportID = " & reportID & _
-
" ORDER BY FirstName, LastName"
-
rs.Open sql, conn
-
if NOT rs.EOF then
-
body = body & "<table border='0' cellspacing='0' cellpadding='3'>"
-
body = body & "<tr><td><b>Site Personnel:</b></td><td>Number of Hours</td></tr>"
-
do until rs.EOF
-
body = body & "<tr><td>" & rs.Fields("FirstName") & " " & rs.Fields("LastName") & "</td><td>" & rs.Fields("Hours") & "</td></tr>"
-
rs.MoveNext
-
Loop
-
end if
-
rs.Close
-
-
'Vehicles on site
-
body = body & "</table>"
-
-
sql = "SELECT * FROM TblReportVehicle WHERE ReportID = " & reportID & _
-
" ORDER BY LicenseNum"
-
rs.Open sql, conn
-
if NOT rs.EOF Then
-
body = body & "<table border='0' cellspacing='0' cellpadding='3'>"
-
body = body & "<tr><td colspan='4'><b>Company Vehicles on site:</b></td></tr>"
-
body = body & "<tr><td width='120'> </td><td>License No</td><td>Milage Start (km)</td><td>Milage Finish (km)</td></tr>"
-
do until rs.EOF
-
body = body & "<tr><td width='120'> </td><td>" & rs.Fields("LicenseNum") & "</td><td>" & rs.Fields("MilageStart") & "</td><td>" & rs.Fields("MilageFinish") &"</td></tr>"
-
rs.MoveNext
-
Loop
-
body = body & "</table>"
-
end if
-
rs.Close
-
-
body = body & "</body></html>"
-
-
'mail.Body = body
-
'mail.AddEmbeddedImage Server.MapPath("/Images/Calendar Email Logo.jpg"), "Logo" ' Embed logo in email body
-
'mail.IsHTML = true
-
-
'Attach pictures to email
-
dim path
-
path = Server.MapPath("Pictures")
-
-
sql = "SELECT * FROM TblReportPicture WHERE ReportID = " & reportID
-
rs.Open sql, conn
-
if NOT rs.EOF then
-
do until rs.EOF
-
mail.AddAttachment path & "/" & rs.Fields("Filename")
-
rs.MoveNext
-
loop
-
end if
-
rs.Close
-
-
On Error Resume Next
-
objMessage.Send
-
set mail = nothing
-
-
if Err <> 0 then
-
Response.Write "We are sorry but an error has occurred when sending email.<br><br>"
-
Response.Write "Error description: " & Err.Description
-
else
-
'Add record to Report Email table
-
rs.Open "TblReportEmail", conn, adOpenKeyset, adLockOptimistic
-
rs.AddNew
-
rs.Fields("EmailTo") = emailTo
-
rs.Fields("Subject") = emailSubject
-
rs.Fields("EmailBy") = Session.Contents("UserFullName")
-
rs.Fields("ReportID") = reportID
-
rs.Update
-
rs.Close
-
-
Response.Write "Report # " & reportID & " has been sent<br><br>"
-
Response.Write "<a href='ReportMain.asp'>Back to Report Main</a>"
-
%>
-
<script type="text/javascript">
-
<!--
-
window.setTimeout("window.location='ReportMain.asp'",2500);
-
-->
-
</script>
-
<%
-
end if
-
end if
-
conn.Close
-
set rs = nothing
-
set rs1 = nothing
-
set conn = nothing
-
%>
-
</td>
-
</tr>
-
</table>
The problem is you keep initializing a new blank variable called "body" and assigning that blank variable to the message body. You then add text to the body variable. You have never assigned any text to the message body. Put all of the text in the body variable BEFORE you assign the message.body = body. Would a diagram help?
Jared
Please a diagram would definately help! Thx sooo much!!
Hi Jared
I figured out what you ment in your last posting. It now works great! Thx a bunch for your help! U saved me a bunch of time!!
Tibor
OK, imagine that when you create a new message (set objMessage = createobject("cdo.message") ) you are asking the server to create a blank email form like this: You go about filling this in with commands like this: - objMessage.To = emailTo
-
objMessage.From = getSetting("pEmailFrom")
-
objMessage.Subject = Request.Form("txtEmailSubject")
Does this make sense so far? Everything up to this point you do right.The problem comes when you try to fill in the body of the email. You have a variable called "body". Because it holds text, let's imagine the variable as a blank text box: When you go to fill in the body of the email, you say - objMessage.HTMLBody = body
This command is fine, and it would work, except that body is your blank text box. There is no text in the text box, so you have just specified that the email body should be blank.
After this you have several lines that look like this: - body = body & "<HTML>..."
This adds text to the variable body BUT IT DOESN'T ADD TEXT TO THE BODY OF THE EMAIL. In other words, your email message looks like this: Where is all the text that you wanted to put in the body of the email? it is in the variable "body": Are you with me so far?
The whole problem boils down to you filling out the body of the email by pointing it to an empty variable - objMessage.HTMLBody = body
there is no text in this variable, so your email body is blank. You spend a lot of time after that putting text into the variable, but not into the body of the email. If you just switched those around (fill in the body of the email AFTER you put text into the variable "body") that would solve your problem.
Jared
jhardman,
Thanks for your awesome post! I was able to solve my problem as well with your detailed explanation :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Timothy Madden |
last post by:
Hy all
In my application I'll receive XML text in the HTTP-message body in a
particular format that only my application understands
My script will be requested by the client with HTTP POST and...
|
by: Notlwonk |
last post by:
I have written an event sink in C# that hooks into our Exchange Server
2000 store.
The sink fires and the various LOG files are created, but for some
reason I cannot seem to read-in the e-mail...
|
by: Kimmo Laine |
last post by:
Hi,
how can i be sure that the MSMQ Message.Body property contains something
valid? If i send the message like this:
public void SendMyMessage( int msgCode, object msgData ) {
Message msg =...
|
by: desi.american |
last post by:
I'm using System.Web.Mail to send an email message from an ASP.NET web
page.
This is the main section of the code.
//************* start code *****************************
string mailHost =...
|
by: dude718 |
last post by:
is there a way to import *.html file to message.body
string element of mailmessage class without have to
actually type it up. Also is the maximum limit to how
much can a string hold.
I have...
|
by: Jitesh Sinha |
last post by:
Hi,
I am running Windows 2003/ IIS 6.0. I was stuck with rather a abnormal
behaviour of System.Web.mail class. It was truncating the message body
after 3,071 character. The code i was testing...
|
by: Andre |
last post by:
Hi folks,
I'm trying to create a sub that e-mails the results of program output
to our accounts receivable manager. I built my CDO code using examples
from a couple newsgroups like this one, so...
|
by: barca933 |
last post by:
hello
I'm using WebDAV in PHP to get messages from Exchange Server
I get all the mailboxes then I get the messages' headers in a specified folder(mailbox)
I also could get the attachments and...
|
by: Soniad |
last post by:
Hello,
I have created a common function in my ASP page to send mail.
so , in every page where mail part is there , this function is called.
I have given three parameters namely : msg,EmailId...
|
by: ravibhartiya |
last post by:
Hi,
I am using the following code for sending email
Sub SendEmail(iOrgId,strEmailFrom,strEmailSubject,strEmailBody,strEmailTo)
Dim ObjEmail
ObjEmail.To=strEmailTo
ObjEmail.From=strEmailFrom...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |