While Sending email through application, no errors, just not receiving messages

Discussion in 'Classic ASP' started by condor, Dec 13, 2005.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. There are a lot of post here on this topic, however I still am unable to get my email/retrieve password functions to work. I get the sent page, saying the message was sent, however I never recieve it. I'm using cdo at the moment.

    Really need this to work soon! Can anyone help?
    Code is as follows:




    'Function to send an e-mail


    Function SendMail(ByVal strEmailBodyMessage, ByVal strRecipientName, ByVal strRecipientEmailAddress, ByVal strFromEmailName, ByVal strFromEmailAddress, ByVal strSubject, strMailComponent, blnHTML)


    on error resume next


    'Dimension variables


    Dim objCDOSYSMail 'Holds the CDOSYS mail object


    Dim objCDOMail 'Holds the CDONTS mail object


    Dim objJMail 'Holds the Jmail object


    Dim objAspEmail 'Holds the Persits AspEmail email object


    Dim objAspMail 'Holds the Server Objects AspMail email object


    Dim strEmailBodyAppendMessage 'Holds the appended email message


    Dim strMailServerUser


    Dim strMailServerPass








    'If you use SMTP authentication enter the username and password in the following variables


    strMailServerUser = "" 'SMTP server username


    strMailServerPass = "" 'SMTP server password











    'Remove unwanted cahracters that may course the email component to throw an exception


    strRecipientName = Replace(strRecipientName, ",", "", 1, -1, 1)


    strFromEmailName = Replace(strFromEmailName, ",", "", 1, -1, 1)


    strRecipientEmailAddress = Replace(strRecipientEmailAddress, ",", "", 1, -1, 1)


    strFromEmailAddress = Replace(strFromEmailAddress, ",", "", 1, -1, 1)


    strRecipientName = Replace(strRecipientName, ";", "", 1, -1, 1)


    strFromEmailName = Replace(strFromEmailName, ";", "", 1, -1, 1)


    strRecipientEmailAddress = Replace(strRecipientEmailAddress, ";", "", 1, -1, 1)


    strFromEmailAddress = Replace(strFromEmailAddress, ";", "", 1, -1, 1)


    strRecipientName = Replace(strRecipientName, ":", "", 1, -1, 1)


    strFromEmailName = Replace(strFromEmailName, ":", "", 1, -1, 1)


    strRecipientEmailAddress = Replace(strRecipientEmailAddress, ":", "", 1, -1, 1)


    strFromEmailAddress = Replace(strFromEmailAddress, ":", "", 1, -1, 1)


    strRecipientName = Replace(strRecipientName, "<", "", 1, -1, 1)


    strFromEmailName = Replace(strFromEmailName, "<", "", 1, -1, 1)


    strRecipientEmailAddress = Replace(strRecipientEmailAddress, "<", "", 1, -1, 1)


    strFromEmailAddress = Replace(strFromEmailAddress, "<", "", 1, -1, 1)


    strRecipientName = Replace(strRecipientName, ">", "", 1, -1, 1)


    strFromEmailName = Replace(strFromEmailName, ">", "", 1, -1, 1)


    strRecipientEmailAddress = Replace(strRecipientEmailAddress, ">", "", 1, -1, 1)


    strFromEmailAddress = Replace(strFromEmailAddress, ">", "", 1, -1, 1)





    'Check the email body doesn't already have Web Wiz Forums


    'If blnLCode Then


    'If HTML format then make an HTML link


    'If blnHTML Then


    'strEmailBodyAppendMessage = "<hr />Powered by <a href=""http://www.webwizforums.com"">Web Wiz Forums</a> version " &amp; strVersion &amp; "Free ASP Bulletin Board System - Download your free copy today!Windows 2003 ASP Web Hosting - <a href=""http://www.webwizhosts.net"">www.webwizhosts.net</a>"


    'Else do a text link


    'Else


    'strEmailBodyAppendMessage = VbCrLf &amp; VbCrLf &amp; "---------------------------------------------------------------------------------------"


    'strEmailBodyAppendMessage = strEmailBodyAppendMessage &amp; VbCrLf &amp; "Powered by Web Wiz Forums version " &amp; strVersion &amp; " - http://www.webwizforums.com"


    'strEmailBodyAppendMessage = strEmailBodyAppendMessage &amp; VbCrLf &amp; "Free ASP Bulletin Board System - Download your free copy today!"


    'strEmailBodyAppendMessage = strEmailBodyAppendMessage &amp; VbCrLf &amp; "Windows 2003 ASP Web Hosting - http://www.webwizhosts.net"


    'End If


    'End If











    '******************************************


    '*** Mail components ****


    '******************************************


    'Select which email component to use


    Select Case strMailComponent








    '******************************************


    '*** MS CDOSYS mail component ****


    '******************************************


    'CDOSYS mail component


    Case "CDOSYS"


    'Dimension variables


    Dim objCDOSYSCon


    Dim intSendUsing





    'Calculate the port we are sendusing (1=localhost 2=network)


    If LCase(strOutgoingMailServer) = "localhost" OR strOutgoingMailServer = "http://127.0.0.1" OR strOutgoingMailServer = "127.0.0.1" Then


    intSendUsing = 1


    Else


    intSendUsing = 2


    End If


    'Create the e-mail server object


    Set objCDOSYSMail = Server.CreateObject("CDO.Message")


    Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")


    'Set and update fields properties


    With objCDOSYSCon





    'Use SMTP Server authentication if required


    If strMailServerUser <> "" AND strMailServerPass <> "" Then


    ' Specify the authentication mechanism to basic (clear-text) authentication cdoBasic = 1


    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1





    'SMTP Server username


    .Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = strMailServerUser





    'SMTP Server password


    .Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strMailServerPass


    End If


    'Out going SMTP server


    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strOutgoingMailServer


    'SMTP port


    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25





    'CDO Port (1=localhost 2=network)


    .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1





    'Set CDO pickup directory if using localhost (CDO Port 1)


    If intSendUsing = 1 Then


    'CDO pickup directory (used for localhost service)


    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"


    End If


    'Timeout


    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60


    .Fields.Update


    End With


    'Update the CDOSYS Configuration


    Set objCDOSYSMail.Configuration = objCDOSYSCon


    With objCDOSYSMail


    'Who the e-mail is from


    .From = strFromEmailName &amp; " <" &amp; strFromEmailAddress &amp; ">"


    'Who the e-mail is sent to


    .To = strRecipientName &amp; " <" &amp; strRecipientEmailAddress &amp; ">"


    'The subject of the e-mail


    .Subject = strSubject


    'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)


    If blnHTML Then


    .HTMLBody = strEmailBodyMessage &amp; strEmailBodyAppendMessage


    Else


    .TextBody = strEmailBodyMessage &amp; strEmailBodyAppendMessage


    End If


    'Send the e-mail


    If NOT strOutgoingMailServer = "" Then .Send


    End with


    'Close the server mail object


    Set objCDOSYSMail = Nothing











    '******************************************


    '*** MS CDONTS mail component ****


    '******************************************


    'CDONTS mail component


    Case "CDONTS"


    'Create the e-mail server object


    Set objCDOMail = Server.CreateObject("CDONTS.NewMail")


    With objCDOMail


    'Who the e-mail is from


    .From = strFromEmailName &amp; " <" &amp; strFromEmailAddress &amp; ">"


    'Who the e-mail is sent to


    .To = strRecipientName &amp; " <" &amp; strRecipientEmailAddress &amp; ">"


    'The subject of the e-mail


    .Subject = strSubject


    'The main body of the e-amil


    .Body = strEmailBodyMessage &amp; strEmailBodyAppendMessage


    'Set the e-mail body format (0=HTML 1=Text)


    If blnHTML Then


    .BodyFormat = 0


    Else


    .BodyFormat = 1


    End If


    'Set the mail format (0=MIME 1=Text)


    .MailFormat = 0


    'Importance of the e-mail (0=Low, 1=Normal, 2=High)


    .Importance = 1


    'Send the e-mail


    .Send


    End With


    'Close the server mail object


    Set objCDOMail = Nothing











    '******************************************


    '*** w3 JMail mail component ****


    '******************************************


    'JMail component


    Case "Jmail"


    'Create the e-mail server object


    Set objJMail = Server.CreateObject("JMail.SMTPMail")


    With objJMail


    'Out going SMTP mail server address


    .ServerAddress = strOutgoingMailServer


    'Who the e-mail is from


    .Sender = strFromEmailAddress


    .SenderName = strFromEmailName


    'Who the e-mail is sent to


    .AddRecipient strRecipientEmailAddress


    'The subject of the e-mail


    .Subject = strSubject


    'Set the e-mail body format (BodyHTML=HTML Body=Text)


    If blnHTML Then


    .HTMLBody = strEmailBodyMessage &amp; strEmailBodyAppendMessage


    Else


    .Body = strEmailBodyMessage &amp; strEmailBodyAppendMessage


    End If


    'Importance of the e-mail


    .Priority = 3


    'Send the e-mail


    If NOT strOutgoingMailServer = "" Then .Execute


    End With


    'Close the server mail object


    Set objJMail = Nothing








    '******************************************


    '*** w3 JMail ver.4+ mail component ****


    '******************************************


    'JMail ver.4+ component (this version allows authentication)


    Case "Jmail4"


    'Create the e-mail server object


    Set objJMail = Server.CreateObject("Jmail.Message")


    With objJMail





    'Send SMTP Server authentication data


    If NOT strMailServerUser = "" Then .MailServerUserName = strMailServerUser


    If NOT strMailServerPass = "" Then .MailServerPassword = strMailServerPass


    'Who the e-mail is from


    .From = strFromEmailAddress


    .FromName = strFromEmailName


    'Who the e-mail is sent to


    .AddRecipient strRecipientEmailAddress, strRecipientName


    'The subject of the e-mail


    .Subject = strSubject


    'Set the e-mail body format (BodyHTML=HTML Body=Text)


    If blnHTML = True Then


    .ContentType = "text/html"


    .HTMLBody = strEmailBodyMessage &amp; strEmailBodyAppendMessage


    Else


    .Body = strEmailBodyMessage &amp; strEmailBodyAppendMessage


    End If


    'Importance of the e-mail


    .Priority = 3


    'Send the e-mail


    If NOT strOutgoingMailServer = "" Then .Send(strOutgoingMailServer)


    End With


    'Close the server mail object


    Set objJMail = Nothing








    '******************************************


    '*** Persits AspEmail mail component ****


    '******************************************


    'AspEmail component


    Case "AspEmail"


    'Create the e-mail server object


    Set objAspEmail = Server.CreateObject("Persits.MailSender")


    With objAspEmail


    'Out going SMTP mail server address


    .Host = strOutgoingMailServer





    'SMTP server username and password


    .Username = strMailServerUser


    .Password = strMailServerPass


    'Who the e-mail is from


    .From = strFromEmailAddress


    .FromName = strFromEmailName


    'Who the e-mail is sent to


    .AddAddress strRecipientEmailAddress


    'The subject of the e-mail


    .Subject = strSubject


    'Set the e-mail body format (BodyHTML=HTML Body=Text)


    If blnHTML Then


    .IsHTML = True


    End If


    'The main body of the e-mail


    .Body = strEmailBodyMessage &amp; strEmailBodyAppendMessage


    'Send the e-mail


    If NOT strOutgoingMailServer = "" Then .Send


    End With








    'Close the server mail object


    Set objAspEmail = Nothing





    '********************************************


    '*** ServerObjects AspMail mail component ***


    '********************************************


    'AspMail component


    Case "AspMail"


    'Create the e-mail server object


    Set objAspMail = Server.CreateObject("SMTPsvg.Mailer")


    With objAspMail


    'Out going SMTP mail server address


    .RemoteHost = strOutgoingMailServer


    'Who the e-mail is from


    .FromAddress = strFromEmailAddress


    .FromName = strFromEmailName


    'Who the e-mail is sent to


    .AddRecipient " ", strRecipientEmailAddress


    'The subject of the e-mail


    .Subject = strSubject


    'Set the e-mail body format (BodyHTML=HTML Body=Text)


    If blnHTML Then


    .ContentType = "text/HTML"


    End If


    'The main body of the e-mail


    .BodyText = strEmailBodyMessage &amp; strEmailBodyAppendMessage


    'Send the e-mail


    If NOT strOutgoingMailServer = "" Then .SendMail


    End With


    'Close the server mail object


    Set objAspMail = Nothing


    End Select


    'Set the returned value of the function to true


    SendMail = True


    on error goto 0


    End Function


    %>
     
  2. This is an incredibly long post,can you trim down the source code a bit? Copy out just the section that actually sends the email.

    Have you created a test page with just the section that sends an email?

    Also could you remove all the lines that are commented out, it makes it hard to read.

    thanks


    Joel Thoms

    DiscountASP.NET
    http://www.DiscountASP.NET
     
  3. Ok, Here is the stripped down version: script for cdo:

    <%
    'Function to send an e-mail
    Function SendMail(ByVal strEmailBodyMessage, ByVal strRecipientName, ByVal strRecipientEmailAddress, ByVal strFromEmailName, ByVal strFromEmailAddress, ByVal strSubject, strMailComponent, blnHTML)
    on error resume next
    'Dimension variables
    Dim objCDOSYSMail'Holds the CDOSYS mail object
    Dim strEmailBodyAppendMessage'Holds the appended email message
    Dim strMailServerUser
    Dim strMailServerPass


    'If you use SMTP authentication enter the username and password in the following variables
    strMailServerUser = "" 'SMTP server username
    strMailServerPass = ""'SMTP server password



    'CDOSYS mail component
    Case "CDOSYS"
    'Dimension variables
    Dim objCDOSYSCon
    Dim intSendUsing

    'Calculate the port we are sendusing (1=localhost 2=network)
    If LCase(strOutgoingMailServer) = "localhost" OR strOutgoingMailServer = "http://127.0.0.1" OR strOutgoingMailServer = "127.0.0.1" Then
    intSendUsing = 1
    Else
    intSendUsing = 2
    End If
    'Create the e-mail server object
    Set objCDOSYSMail = Server.CreateObject("CDO.Message")
    Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
    'Set and update fields properties
    With objCDOSYSCon

    'Use SMTP Server authentication if required
    If strMailServerUser <> "" AND strMailServerPass <> "" Then
    ' Specify the authentication mechanism to basic (clear-text) authentication cdoBasic = 1
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

    'SMTP Server username
    .Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = strMailServerUser

    'SMTP Server password
    .Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strMailServerPass
    End If
    'Out going SMTP server
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strOutgoingMailServer
    'SMTP port
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

    'CDO Port (1=localhost 2=network)
    .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1

    'Set CDO pickup directory if using localhost (CDO Port 1)
    If intSendUsing = 1 Then
    'CDO pickup directory (used for localhost service)
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"
    End If
    'Timeout
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    .Fields.Update
    End With
    'Update the CDOSYS Configuration
    Set objCDOSYSMail.Configuration = objCDOSYSCon
    With objCDOSYSMail
    'Who the e-mail is from
    .From = strFromEmailName &amp; " <" &amp; strFromEmailAddress &amp; ">"
    'Who the e-mail is sent to
    .To = strRecipientName &amp; " <" &amp; strRecipientEmailAddress &amp; ">"
    'The subject of the e-mail
    .Subject = strSubject
    'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)
    If blnHTML Then
    .HTMLBody = strEmailBodyMessage &amp; strEmailBodyAppendMessage
    Else
    .TextBody = strEmailBodyMessage &amp; strEmailBodyAppendMessage
    End If
    'Send the e-mail
    If NOT strOutgoingMailServer = "" Then .Send
    End with
    'Close the server mail object
    Set objCDOSYSMail = Nothing
    'Set the returned value of the function to true
    SendMail = True
    on error goto 0
    End Function
    %>
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    One problem I see is that you are trying to dump the mail to the pick up directory if using localhost. However, the pickup directory path is wrong. Try e:\inetpub\mailroot\pickup

    Also try using port to send and see if it works.

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  5. here is the real shortened version
    /emoticons/turn.gif /emoticons/turn.gif /emoticons/turn.gif

     
  6. Too unreal! I just grabbed the web wiz forums too, and the instruction to"Try e:\inetpub\mailroot\pickup" fixed me.

    Now THAT'S a good use of tech support forums.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page