Gmail SMTP not working

Discussion in 'Programming' started by puneet_pr, Apr 2, 2012.

  1. #1
    I have one application which I create in ASP. But from few days email function not working. Can anyone help me.

    This is the code

    ----------Code start----------
    <%
    txtBodyT="<table style='background-color:#CCCCCC; border-bottom-color:#CCCCCC; border-bottom-style:solid; border-bottom-width:0px; border-top-color:#CCCCCC; border-top-style:solid; border-top-width:0px; border-left-color:#CCCCCC; border-left-style:solid; border-left-width:40px; border-right-color:#CCCCCC; border-right-style:solid; border-right-width:40px;' width='70%'>"
    txtBodyT=txtBodyT&"<tr>"
    txtBodyT=txtBodyT&"<td>"
    txtBodyT=txtBodyT&html
    txtBodyT=txtBodyT&"</td>"
    txtBodyT=txtBodyT&"</tr>"
    txtBodyT=txtBodyT&"</table>"
    subjectM="DIAL HR Apply for "& txtTotalApply &" "&txtLeaveType'"Test Send mail from localhost"
    Set objMessage = CreateObject("CDO.Message")
    objMessage.Subject = subjectM
    objMessage.From = txtFromEmail
    objMessage.To = txtNPEMAIL
    objMessage.CC = "dialhr2011@gmail.com"
    'objMessage.BCC = "puneet.rawat@gdfsuez.com"
    objMessage.HTMLBody = txtBodyT
    'objMessage.TextBody = html'"This is some sample message text."

    '==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") = "smtp.gmail.com" 'dbserver1.tractebel.net.in smtp.gmail.com

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

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

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

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

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

    '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

    If intSendUsing = 1 Then
    'objMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"
    End If

    objMessage.Configuration.Fields.Update

    '==End remote SMTP server configuration section==
    on error resume next
    objMessage.Send
    if err<>0 then
    'Response.Write(err.File&"<br />")
    Response.Write(err.Number&"<br />")
    Response.Write(err.Description&"<br />")
    Response.Write(err.Source&"<br />")
    else
    Response.Write("<br />Message Send... :)<br/>" & txtBodyT)
    end if
    Response.Write("<br />Message Send... :)<br/>" & txtBodyT)
    %>

    ----------Code End----------
     
    puneet_pr, Apr 2, 2012 IP
  2. snowelephant

    snowelephant Peon

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Are you getting an error message, or just not receiving the email? You might want to start by testing connectivity to the gmail server, and make sure the password is correct. It's possible that it is actually working, but the email is going into your spam box, or hitting a mail rule in your inbox. You can also try installing Wireshark, which will monitor network traffic going out of your machine - then at least you could see if the code is contacting the gmail server at all.
     
    snowelephant, Apr 6, 2012 IP