Click to See Complete Forum and Search --> : autopopulating the email "From" field
LuigiX
10-16-2003, 12:53 PM
HI
Without knowing too much about ASP, I've got a hunch this is where I'll find the answer.
I've got a form which is sent over the company intranet (NT/IIS based) to an addressee group.
When the form is submitted I want the code to populate the "From" field of the email with the user's login name eg
From:J.Bloggs@mycmopany.com
Cheers
Luigi
simflex
10-16-2003, 04:59 PM
let's see if this helps:
<%Dim Pears
Set Pears = Server.CreateObject("ADODB.Connection")
Conn = "DRIVER={Microsoft Access Driver (*.mdb)}; "
Conn = Conn & "DBQ=" & Server.MapPath("db\users.mdb")
Pears.Open(Conn)
SQLtemp2 = "SELECT FROM_UserID FROM password WHERE userID = '" & username & "'"
Set rst = Pears.Execute(SQLtemp2)%>
<%
UserName = rst("userid")
'code for sending email. This will one work on windows 2000 or windows xp.
Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Dim iBp
Dim Flds
Dim iConf
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
Flds(cdoSendUsingMethod) = cdoSendUsingPort
Flds(cdoSMTPServer) = "serverName"
Flds(cdoSMTPServerPort) = 25
Flds(cdoSMTPAuthenticate) = cdoAnonymous ' 0
Flds.Update
With iMsg
Set .Configuration = iConf
.From = ""&username&""
.To = "whoever"
.Subject = "Subject."
.TextBody = "Message"
.Send
End With
%>
Hope snippet doesn't mean it is ready to ship but it it will hopefully give you some pretty give idea.
Note: this works for windows 2k and xp.
If your op is earlier then you want to look at cdonts.newmail.
LuigiX
10-17-2003, 02:25 PM
Simflex you are a legend!
Cheers
Luigi
LuigiX
10-17-2003, 02:31 PM
Actaully Simflex could you clarify your last comment re CDonts.
Also could you give your thoughts on CDonts or ASP,mail as the best email client?
Cheers again Luigi
simflex
10-17-2003, 02:41 PM
first of all, I am far from being a legend but thanks for the kind words.
I have benefitted a lot from this forum from the likes of Dave Clark and others but most notably [SW]Ribeyed.
This is just my small way of saying thanks to them.
About my thoughts, it all depends, I think on what you are trying to accomplish, the operating system you are using and the way your mail server is setup.
I have only used CDONTs for writing stored procedures and CDO because I have windows 200 and/or XP.
What mail client you use depends on your op, your need and your mail server.
Someone might give a better info than I did, sorry.