Results 1 to 14 of 14

Thread: send email

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    2

    send email

    I am very sorry when i disturb to you.
    I have some problem with my send email code.
    when i submit it run okey but i can not receive email.
    Please help me to check my code

    Code:
    		Customertype=Request.Form("Customertype")
    				senderemail=Request.Form("email")
                    phone=Request.Form("phone")
                    subject=Request.Form("subject")
    				note=Request.Form("note")
    				
    				CustomerType=replace(CustomerType,"'","''")
    				senderemail=replace(senderemail,"'","''")
    				phone=replace(phone,"'","''")
    				subject=replace(subject,"'","''")
    				note=replace(note,"'","''")
    				
    				if 	Customertype="NTL" then
                       	cFromB ="[email protected]"
                        else
                         if Customertype="SGL" then
                           cFromB ="[email protected]"
                         else
                      	  cFromB="[email protected]"		
                        end if
                     end if
                            
                         	SubjectText = "Infomation - " 
                            nd = "Information" & VbCrLf & VbCrLf
                            nd = nd & "1. Information:" & VbCrLf
                            nd = nd & "Customertype: " & Customertype & VbCrLf 
    						nd = nd & "Email: " & senderemail & VbCrLf 
    					    nd = nd & "You have recived from : " & cFrom & VbCrLf 
    						nd = nd & "Phone: " & phone & VbCrLf
    						nd = nd & "Subject: " & subject & VbCrLf
    					   	nd = nd & "2. Noi dung lien lac:" & VbCrLf
                            nd = nd & "Comment: " & note & VbCrLf
      
    	    DIM oMail, Flds, oMailConfig
    		Set oMail = Server.CreateObject("CDO.Message")
    		Set oMailConfig = CreateObject("CDO.Configuration")
    		oMailConfig.Fields("(URL address blocked: See forum rules)") = "localhost" 
    		oMailConfig.Fields("(URL address blocked: See forum rules)") = 25 
    		oMailConfig.Fields("(URL address blocked: See forum rules)") = 2 
    		oMailConfig.Fields("(URL address blocked: See forum rules)") = 60 
    		oMailConfig.Fields.Update
    		Set oMail.Configuration = oMailConfig
    		oMail.From = cFromB
    		oMail.To = senderemail
         
    		oMail.Subject= SubjectText
    		oMail.TextBody = nd
    		oMail.Send
    				
    		Set oMail = Nothing 
    		Set oMailConfig = Nothing

    Thanks.
    Regards
    Hoang Phuc

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: send email

    What error are you receiving?
    Sending an email is as simple as...


    Code:
    Set objEmail = CreateObject("CDO.Message")
    objEmail.From = "your email here"
    objEmail.To = "recipients email here"
    objEmail.Subject = "subject of email"
    objEmail.Textbody = "a message to send"
    objEmail.Send

  3. #3
    New Member
    Join Date
    Mar 2008
    Posts
    4

    Question Re: send email

    Hi Paul,
    I am using the code:
    Set objEmail = CreateObject("CDO.Message")
    objEmail.From = "your email here"
    objEmail.To = "recipients email here"
    objEmail.Subject = "subject of email"
    objEmail.Textbody = "a message to send"
    objEmail.Send

    to try to send an email. I have copied it to notepad and saved it as a .vbp.
    when I try to run the script I get an error message saying "Error: the "send using" configuration value is invalid.

    Any ideas?

  4. #4
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: send email

    You need to save it with the .vbs extension and then run it. Also if it errors check what line and column it specifies.

  5. #5
    New Member
    Join Date
    Mar 2008
    Posts
    4

    Re: send email

    Hi Paul,
    Many thanks for you reply.
    I did save the file as a .vbs (sorry)

    When I run the scipt I receive the message:

    script: c:\...........email.vbs
    Line: 6
    Char: 1
    Error: The "SendUsing" configuration value is invalid
    Code: 80040220
    Source: CDO.Message.1

    I have put valid email addresses in the from and to lines.

    Have you any ideas?

  6. #6
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: send email

    Did you happen to change line 6 at all? It appears to be working perfectly fine for me.

  7. #7
    New Member
    Join Date
    Mar 2008
    Posts
    4

    Re: send email

    No, I have not changed anything apart from entering a valid from and to email address.

    When you say it works for you, what is the autcome when you activate the script?

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: send email

    works fine for me
    you need to change your configuation, sendusing refers to the server authentication
    Sending a text email using authentication against a remote SMTP server.

    More and more administrators are restricting access to their servers to control spam or limit
    which users may utilize the server. This example shows you how to use basic authentication,
    the most commonly used authentication method, when the SMTP server you are using requires it.

    This code is slightly more complex but not very difficult to understand or work with.

    Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
    Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
    mine is set to 2

    '==This section provides the configuration information for the remote SMTP server.

    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

    'Name or IP of Remote SMTP Server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.your.com"

    'Type of authentication, NONE, Basic (Base64 encoded), NTLM
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

    'Your UserID on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid"

    'Your password on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"

    'Server port (typically 25)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

    'Use SSL for the connection (False or True)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

    'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

    objMessage.Configuration.Fields.Update

    '==End remote SMTP server configuration section==

    objMessage.Send
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9
    New Member
    Join Date
    Mar 2008
    Posts
    4

    Re: send email

    Hi Pete,
    Many thanks for the info but not to sure what to do with it!

    returning back to my original code - what do i have to add to make it send an email?
    kind regards
    Darren

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: send email

    prior to your original code you need to set the cdo configuration as i indicated above, see the first item in the second quote block
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11
    Lively Member
    Join Date
    Nov 2006
    Posts
    105

    Re: send email

    Westconn,
    One question: what is this website run my microsoft? is it secure? can i trust sending p/w's over this channel (since the p/w is not encoded)

    OR is there a way to encode the p/w and email information before sending it to the schemas.microsoft.com site?

    btw, it works like a charm! thanks a million.... unless there is a security issue, in which case, thanks 1/2 million.

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: send email

    i believe the schemas are on the local machine, regardless of appearance, though this might be a mistaken concept
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  13. #13
    Lively Member
    Join Date
    Nov 2006
    Posts
    105

    Re: send email

    from the microsoft technet site (http://www.microsoft.com/technet/scr...4/hey1129.mspx)

    By the way, these URIs concern a lot of people: they wonder why they need to connect to Microsoft in order to send an email. The truth is, you don’t actually connect to Microsoft; these URIs are just properties. Why are they referenced like this? To be honest, we don’t know. But don’t worry: your mail doesn’t get routed through Microsoft, and no one here reads it. Trust us, we have enough problems keeping up with our own email, let alone taking time to read someone else’s.

    Now, what about adding an attachment to this email? All it takes is one additional line of code, much like this line which attaches the files C:\Scripts\Output.txt to the email:

    objEmail.AddAttachment "C:\Scripts\Output.txt"

    That’s it; add this line of code to the script, and you’ll have yourself an attachment. The entire script will look something like this:

    Set objEmail = CreateObject("CDO.Message")

    objEmail.From = "[email protected]"
    objEmail.To = "[email protected]"
    objEmail.Subject = "Server down"
    objEmail.Textbody = "Server1 is no longer accessible over the network."
    objEmail.AddAttachment "C:\Scripts\Output.txt"

    objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
    "smtpmailer"
    objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update

    objEmail.Send

    As long as we have your attention, we’ve had a couple people ask us how they can send email if their SMTP server requires authentication. To tell you the truth, that’s a tough question for us to answer because (for various reasons) we don’t have a way to test that scenario. However, adding a user name and password to your script is a good place to start:


    objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "fabrikam\kenmyer"
    objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "&gr54#wgha"

    The preceding code logs you on to the SMTP server as fabrikam\kenmyer, with the password &gr54#wgha. Note that this does send the user name and password in cleartext. Consequently, you probably don’t want to send email using an Administrator account. Instead, create a user account that has the right to send email (but little, if anything else) and log on using that account. For more information, check out the official CDO documentation on MSDN.

  14. #14
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: send email

    as far as sending username/password in clear text, it is only the same as any other email client

    nice find vbrookie
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width