Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 mail script

Author  Topic 

Mlucas1
Starting Member

5 Posts

Posted - 2006-08-10 : 15:47:50
OK I am pretty new to this stuff. I hired programmers who left me in the lurch so I am trying to figure things out on my own I am having some real problems with the mailer scripts

I have inserted some code I got one script working but having probs with this one. Any help appreciated!

Also to note is "EMail an alias from User table because there is only an "email" column not EMail...


<%
cn = Session("cnn")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = cn

If Request.Form("btOk.x") > "0" then
sFEmail = Request.Form("EMail")
FromName = Request.Form("sYName")
sYEmail = Request.Form("sYEmail")
sIdTalent= Request.Form("sIdTalent")
Message = Request.Form("sMessage")


If Len(sFEmail) > 3 and InStr(1, sFEmail, "@") > 1 then
If Len(sYEmail) > 3 and InStr(1, sYEmail, "@") > 1 then

sQuery = "Select EMail From Table Where UserId = " &sIdTalent
rs.Source = sQuery
rs.Open
If not rs.EOF then

' THIS SENDS AN EMAIL TO SOMEONE TELLING THEM ABOUT THE NEW REGISTRATION
REM Message body
TextHeader = "This message is For :" & Chr(13) & Chr(10)
TextEnd = Chr(13) & Chr(10) & Chr(13) & Chr(10) & "Thank You"
FromName = "sYName" & Chr(13) & Chr(10)
Message = "sMessage" & VbCrLf & "http://" & Chr(13) & Chr(10) & Comments & Chr(13) & Chr(10)


Dim Mailer
Dim sMessage
Dim FromName
Dim sFEmail
Dim sYEmail

Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.RemoteHost = "smtp.server.cot"
Mailer.FromName = "FromName"
Mailer.FromAddress = sYEmail
Mailer.AddRecipient sFEmail, Request.Form("email")
Mailer.BodyText = TextHeader & vbCrLf & Chr(13) & Chr(10) & Message & TextEnd
Mailer.Subject = "anything"


Mailer.SendMail
if Mailer.SendMail then

Response.Write "Ok ! Your message send to !..."

else

Response.Write "Mail send failure. Error was " & Mailer.Response

end if
%>

<h3><font color="green">Ok ! Your Message is sent to <%=FirstName%> (of Talent would be nice!!!!)
!</font></h3>

<% else %>

<font color=""red"">Error send message ! EMail address not valid !</font>
<%
End if

rs.Close

Else

If Request.QueryString("Id") > "0" then
sIdTalent = Request.QueryString("Id")
Else

If Session("iUserId") > 0 then
sUserId = CStr(Session("iUserId"))
End If

sQuery = "Select * From Table Where UserId = " &sUserId
rs.Source = sQuery
rs.Open

If rs.EOF then
sYName = ""
sYEmail = ""
Else
sYName = rs.Fields("FirstName").value&" "&rs.Fields("MiddleName").value&" "&rs.Fields("LastName").value
sYEmail = rs.Fields("email").value
sFEmail = rs.fields("EMail").Value
End If

rs.Close

End If
End If
End If
End If

%>

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-08-10 : 16:51:55
If you tell us specifically what the problem is (error messages? emails not sent? going to wrong place? etc) I bet we will be able to help you, or if you ask a specific question.

- Jeff
Go to Top of Page

Mlucas1
Starting Member

5 Posts

Posted - 2006-08-11 : 09:52:10
Ok

I am not getting any errors. When i press submit it just basically reloads

But I am also not getting aqn email either.
And none of the sent or not sent messages are showing up.

Like I said I didn't write the whole script so

A. I am not sure if it sends an email using the users address or if Fromadress should be the host email address with users email address attached.

I am still working on it

Thanks

Go to Top of Page

KenW
Constraint Violating Yak Guru

391 Posts

Posted - 2006-08-11 : 14:42:12
quote:
Originally posted by Mlucas1

OK I am pretty new to this stuff. I hired programmers who left me in the lurch so I am trying to figure things out on my own I am having some real problems with the mailer scripts

I have inserted some code I got one script working but having probs with this one. Any help appreciated!



Gee... Where to begin? :-)

First, when posting here, mark your code as code (see the little button on the toolbar marked with '#'). It makes it much easier to read, because it will retain the formatting.

Ok...


<%
cn = Session("cnn")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = cn

If Request.Form("btOk.x") > "0" then
sFEmail = Request.Form("EMail")
FromName = Request.Form("sYName")
sYEmail = Request.Form("sYEmail")
sIdTalent= Request.Form("sIdTalent")
Message = Request.Form("sMessage")


If Len(sFEmail) > 3 and InStr(1, sFEmail, "@") > 1 then
If Len(sYEmail) > 3 and InStr(1, sYEmail, "@") > 1 then

sQuery = "Select EMail From Table Where UserId = " &sIdTalent
rs.Source = sQuery
rs.Open
If not rs.EOF then

' THIS SENDS AN EMAIL TO SOMEONE TELLING THEM ABOUT THE NEW
' REGISTRATION
'REM Message body


To this point, the only issue seems to be the line starting with REM. AFAIK, VBScript doesn't use that as a comment, so your code should blow up there.


TextHeader = "This message is For :" & Chr(13) & Chr(10)


I presume that you don't know that 'vbCRLF' is the same thing as 'Chr(13) & Chr(10)', except 'vbCRLF' is a lot shorter to type and easier to read. :-)

So the lines should have every instance of 'Chr(13) & Chr(10)' replaced with 'vbCRLF'.

 
FromName = "sYName" & Chr(13) & Chr(10)
Message = "sMessage" & VbCrLf & "http://" & Chr(13) & Chr(10) & Comments & Chr(13) & Chr(10)


I don't think you're accomplishing what you want here. By putting the "sYName" and "sMessage" in quotes, you're using them literally instead of using the values they contain (which you've read from Request.Form() above).

Instead, use 'FromName = sYName & vbCRLF'; do the same thing with Message.


Dim Mailer
Dim sMessage
Dim FromName
Dim sFEmail
Dim sYEmail


Another problem. Since you've already DIM'd FromName above, you can't DIM it again here without replacing the value you just finished assigning to it. I'd suggest you move all of your DIM statements up to the top of your code (right below the '<%' that starts it), and remove all duplicates.


Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.RemoteHost = "smtp.server.cot"
Mailer.FromName = "FromName"


You have the same problem with double quotes around "FromName" as you did with the "sYName" above. Remove the quotes.


Mailer.AddRecipient sFEmail, Request.Form("email")


I'm not sure what you're doing here. You're adding Request.Form("email") as a recipient twice - once from the sFEMail variable, and a second time by getting it from Request.Form("email").


Mailer.BodyText = TextHeader & vbCrLf & Chr(13) & Chr(10) & Message & TextEnd
Mailer.Subject = "anything"


Same here with the vbCRLF/Chr(13) & Chr(10).

The rest of the code doesn't look too bad, although you might be missing a couple of EndIf statements; I can't tell with the formatting the way it is.

Ken
Go to Top of Page

KenW
Constraint Violating Yak Guru

391 Posts

Posted - 2006-08-11 : 14:43:04
Jeff,

quote:
Originally posted by jsmith8858

If you tell us specifically what the problem is (error messages? emails not sent? going to wrong place? etc) I bet we will be able to help you, or if you ask a specific question.

- Jeff



Didn't look too hard, did you?
Go to Top of Page

Mlucas1
Starting Member

5 Posts

Posted - 2006-08-11 : 18:36:28
I cleared up the code some.
I am a litle confused about how I am getting the EMAIL address of of the person we are sending to.

sIdTalent - is a seperate table that does not hold the rs.email the ID is linked to another table that holds the email address.as a matter of fact this script calls on both the User ID Email and Sendee ID email which are both located in the User Table

Hence
Select EMail From User Where UserId = " &sIdTalent
So the sldTalent (Dif table) should look up the email address which is located in the User Table that corresponds with the Talent data.





<%

Dim Mailer
Dim sName
Dim sMessage
Dim sFEmail
Dim sYEmail

cn = Session("cnn")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = cn

If Request.Form("btOk.x") > "0" then

sFEmail = Request.Form("EMail")
sName = Request.Form("sYName")
sYEmail = Request.Form("sYEmail")
sIdTalent= Request.Form("sIdTalent")
Message = Request.Form("sMessage")

If Len(sEmail) > 3 and InStr(1, sEmail, "@") > 1 then
If Len(sYEmail) > 3 and InStr(1, sYEmail, "@") > 1 then

sQuery = "Select EMail From User Where UserId = " &sIdTalent
rs.Source = sQuery
rs.Open
If not rs.EOF then
sFEmail = rs.Fields("EMail").Value
' THIS SENDS AN EMAIL TO Talent
Message body
TextHeader = "This message is For :" & Chr(13) & Chr(10)
TextEnd = Chr(13) & Chr(10) & Chr(13) & Chr(10) & "Thank You"
msgComments = Message & Chr(13) & Chr(10) & "http://www." & Chr(13) & Chr(10)

Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.RemoteHost = "smtp.server.net"
Mailer.FromName = sName
Mailer.FromAddress = sYEMail
Mailer.AddRecipient sEmail
Mailer.BodyText = TextHeader & vbCrLf & Chr(13) & Chr(10) & msgComments & TextEnd
Mailer.Subject = "Hello Talent"

Mailer.SendMail
if Mailer.SendMail then

Response.Write "<h3><font color="green">Ok ! Your Message is sent to
!</font></h3>"

else

Response.Write "<font color=""red"">Error send message ! EMail address not valid !</font> " & Mailer.Response

end if

rs.Close

Else

If Request.QueryString("Id") > "0" then
sIdTalent = Request.QueryString("Id")

Else

If Session("iUserId") > 0 then
sUserId = CStr(Session("iUserId"))
End If

sQuery = "Select * From Table Where UserId = " &sUserId
rs.Source = sQuery
rs.Open

If rs.EOF then
sYName = ""
sYEmail = ""
Else
sYName = rs.Fields("FirstName").value&" "&rs.Fields("MiddleName").value&" "&rs.Fields("LastName").value
sYEmail = rs.Fields("email").value
sFEmail = rs.Fields("EMail").Value


rs.Close
' need all these end ifs to stop error
End If
End If
End If
End If
End If
%>
Go to Top of Page

Mlucas1
Starting Member

5 Posts

Posted - 2006-08-21 : 14:06:33
somehow I got it working thanks
Go to Top of Page
   

- Advertisement -