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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URgent: Mail scripts in ASP.. Needed ASAP.

Status
Not open for further replies.

roytheboy

Programmer
Aug 18, 2002
58
0
0
GB
Hi All,

I'll post some code underneath this in a mo.

Question is about the mailhost in a typical ASP scripts.

I have a domain and this domain is hosted on different servers to mine. So therefore email and everything goes through another box, and this is the IP that is registered in DNS around the globe. Normal setup for a domain for email and web etc... I.e. domain is hosted on different servers to me.

On the WWW. subdomain there is an A record that points directly to my box. i.e. my domain appears in On my box it is configured to capture and direct it to a website.
This all works absolutely dandy.

However when I configure the mailscript to send to SOMEONE@domain123.co.uk from a contacts page I have issues.

If I send to ANY other domain, Hotmail, Zen, various other domains owned and managed by me or not as in the case with hotmail they ALWAYS are received.

There is another IT company involved that looks after the domain name on their servers (or ones they have sourced anyway).

And that state that the mailhost needs to point to mail.domain123.co.uk for it to EVER work, not localhost as it is now.

There is a dummy mail account called web@domain123.co.uk that it sends from on my box.

With localhost it has worked very well for 8 months now, but recently there was a problem and apparently it is down to it being localhost. This must be rubbish as it has worked for 8 months ok. I suspect there is something else in all this. On my box nothing has changed for the domain/DNS/web hosting and frankly ... NOTHING full stop on the box.

Can you please review my code and tell me if my config should work .. (IT has for 8 months) and if the other config should work any differently.

Thanks for reading:

BTW - This is script has been used many times over successfully. It is simply that only the A record points to the site not the entire domain. Thats the slightly different setup:

So the code below has worked great. Now though I am told that it will only work in mail.host is set to mail.domain123.co.uk. even though it has worked.. I think someone is trying to mess me about.... and the client. So Please this is an urgent one.. 500 points job.

Thanks all

Romolo

@@@@@@@@@@@@@@@@@@@@@@@@@@@


<%
FUNCTION FixDate(str)
datestr = cdate(str)
mStr = month(datestr): dStr = day(datestr): yStr = year(datestr)
if (Clng(mStr)<10 and len(mStr)=1) then mStr = "0" & mStr
if (Clng(dStr)<10 and len(dStr)=1) then dStr = "0" & dStr
FixDate = dStr & "/" & mStr & "/" & yStr
END FUNCTION

FUNCTION FixString(str)
FixString = trim(str)
FixString = replace(FixString,"'","''")
FixString = replace(FixString,vbcrlf,"<BR>")

END FUNCTION

FUNCTION UnFixString(str)
UnFixString = trim(str)
UnFixString = replace(UnFixString,"''","'")
UnFixString = replace(UnFixString,"<BR>",vbcrlf)

END FUNCTION


Dim strQuery
Dim strConnection
Dim strID

strID=Trim(Request.querystring("ID"))


Set objConn=CreateObject("ADODB.Connection")
objConn.Open "databasename", "username", "password"




strQUERY = "SELECT AREA FROM thankyou where STATE ='A' ORDER by ID DESC;"

Set catRS = objConn.Execute(strQUERY)

IF catRS.EOF Then
strRecords=0
Else
strRecords=1
End If

strTEXT=trim(catRS.Fields("AREA"))



catRS.Close: SET carRS=nothing





'================================================================
' ***** Read in all variables *****
'================================================================
strTITLE=FixString(request("TITLE"))
strNAME=trim(request("FNAME"))
strSURNAME=trim(request("requiredSURNAME"))
strPHONE=trim(request("PHONE"))
strADDRESS1=trim(request("ADDRESS1"))
strADDRESS2=trim(request("ADDRESS2"))
strTOWN=trim(request("TOWN"))
strPOSTCODE=trim(request("POSTCODE"))
strEMAIL=trim(request("requiredEMAIL"))

strENQUIRY=trim(request("ENQUIRY"))
strCOMMENTS=trim(request("COMMENTS"))
'================================================================
' ***** Main body of ASP *****
'================================================================



' EMAIL ADDRESS OF WHERE CONTACT FORM IS SENT TO


'---------------------------------------------------
'****************************************************
strTo="someone@domain123.co.uk"


'****************************************************
'---------------------------------------------------
strSubject="Contact from website"

' BODY OF EMAIL IS CREATED HERE

strBody="Contact from website:-"&vbcrlf&vbcrlf
strBody=strBody&"NAME: "&strTITLE&" "&strNAME&" "&strSURNAME&vbcrlf
strBody=strBody&"E-MAIL ADDRESS: "&strEMAIL&vbcrlf&vbcrlf
strBody=strBody&"PHONE: "&strPHONE&vbcrlf&vbcrlf
strBody=strBody&"ADDRESS1: "&strADDRESS1&vbcrlf
strBody=strBody&"ADDRESS2: "&strADDRESS2&vbcrlf
strBody=strBody&"TOWN: "&strTOWN&vbcrlf
strBody=strBody&"POSTCODE: "&strPOSTCODE&vbcrlf&vbcrlf
strBody=strBody&"ENQUIRY: "&vbcrlf&strENQUIRY&vbcrlf&vbcrlf
strBody=strBody&"COMMENTS: "&vbcrlf&strCOMMENTS&vbcrlf&vbcrlf

' LEAVE THESE ALONE
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "localhost"
Mail.Port = 25


' THIS NEEDS TO BE AN ACTUAL EMAIL ADDRESS FOR DOMAIN NAME
'---------------------------------------------------
'****************************************************
Mail.From = "web@domain123.co.uk" ' Required

'****************************************************
'---------------------------------------------------

' THIS IS OPTIONAL AND APPEARS AS THE SENDER INSTEAD OF THE EMAIL ADDRESS
Mail.FromName = "website" ' Optional

' LEAVE THESE ALONE
Mail.AddAddress ""&strTo&"", ""
'---------------------------------------------------
'****************************************************
'Mail.AddCC "cc@anotherdomain.co.uk" ' Name is optional
'****************************************************
'---------------------------------------------------

Mail.Subject = ""&strSubject&""
Mail.Body = ""&strBody&""
Mail.Send


' ALL DONE

'YOU CAN THEN EITHER HAVE THE THANK YOU PAGE DISPLAYED IN HTML BELOW THE ASP OR YOU
'CAN JUST RE-DIRECT TO A THANK YOU PAGE, E.G.



%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

Thank you page HTML

</html>

@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
I didn't have a chance to read through your code, but basically it sounds as if the company hosting your server has upgraded their security.

All you should need to do is use their SMTP server as the SMTP server in your code and use a from address that they have configured. If they are using some sort of SMTP authentication you will need to add that user in, but at the least they are likely making sure that your from address is a valid address to send from (to reduce people trying to send spam out through their server).

So change the Mail.Host line and Mail.From line and you should be good.

 
Yes BUT

can localhost EVER be used.

I believe yes... Many others do

Can you confirm please, thanks

Romolo
 
Localhost can be used, it's just another server. Provided your server has a mail server on it (or with IIS a virtual mail server and a forwarding server) then yes, localhost will work.

My two guesses are that either the provider has locked down where email can come from (a lot of provider's do to reduce spam creation) or your server is setup to use IIS's virtual SMTP server which really links into another server and the provider has either turned off relaying altogether or has added a requirement that the from address be a mail account registered with there mail server. Again, this is usually done to combat spam generation.

-T

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top