Sending mail in asp

Discussion in 'C#' started by rag84dec, Apr 3, 2008.

  1. #1
    Hi ,
    My simple code to send mail is this
    
    
    <%
    sch = "http://schemas.microsoft.com/cdo/configuration/" 
     
        Set cdoConfig = CreateObject("CDO.Configuration") 
     
        With cdoConfig.Fields 
            .Item(sch & "sendusing") = 2 ' cdoSendUsingPort 
            .Item(sch & "smtpserver") = "<enter_mail.server_here>" 
            .update 
        End With 
     
        Set cdoMessage = CreateObject("CDO.Message") 
     
        With cdoMessage 
            Set .Configuration = cdoConfig 
            .From = "rag84dec@gmail.com" 
            .To = "rag84dec@gmail.com" 
            .Subject = "Sample CDO Message" 
            .TextBody = "This is a test for CDO.message" 
            .Send 
        End With 
     
        Set cdoMessage = Nothing 
        Set cdoConfig = Nothing 
    
    					
    					%>
    
    Code (markup):

    But it is giving me an error
    
    Error Type:
    CDO.Message.1 (0x80040213)
    The transport failed to connect to the server. 
    /testmail.asp, line 21
    
    
    
    
    Code (markup):
    Can any one help me please
     
    rag84dec, Apr 3, 2008 IP
  2. nubsii

    nubsii Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hi rag,

    You need a way to give them your password, and connect to gmail smtpserver.

    Try something like
    
    Dim SmtpServer As New SmtpClient()
    SmtpServer.Credentials = New Net.NetworkCredential("rag84dec@gmail.com", "###RAG84's PASSWORD###")
    SmtpServer.Port = 587
    SmtpServer.Host = "smtp.gmail.com"
    SmtpServer.EnableSsl = True
    
    Code (markup):
    there might be a way to do that with your ".item" - i've never done it that way though

    then maybe something like this

    
    Dim mail As New MailMessage()
    mail = New MailMEssage()
    mail.From =  New MailAddress("rag84dec@gmail.com","rag",System.Text.Encoding.UTF8)
    mail.To = "rag84dec@gmail.com" 
    mail.Subject = "hihihi subject" 
    mail.TextBody = "This is a test message" 
    
    Code (markup):
    sorry if its a bit sloppy i dont do VB code

    Ideally there would be some try/catch magic in there, and maybe some delivery/replyTo stuff as well...

    Hope that helps!
    Peace.
     
    nubsii, Apr 3, 2008 IP
  3. nubsii

    nubsii Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hmmmm CDO......
    Pardon my previous c0de (though i think it would work)

    This is more inline with the code you posted:

    
    .Item(sch & "sendusing") = 2
    .Item(sch & "smtpserver") = "smtp.gmail.com" 
    .Item(sch & "smtpserverport") = ???//Something need to go here and im not sure what
    .Item(sch & "smtpauthenticate") = 1
    .Item(sch & "sendusername") = "mymail@gmail.com"
    .Item(sch & "sendpassword") =  "mypassword"
    .Item(sch & "smtpusessl") = 1
    .Update
    
    Code (markup):
    I dont know which port to use.... 465?

    In any case i think this might be more the type of thing you want.

    Cheers m8
     
    nubsii, Apr 3, 2008 IP
  4. rag84dec

    rag84dec Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    
    <%
    sch = "http://schemas.microsoft.com/cdo/configuration/" 
     
        Set cdoConfig = CreateObject("CDO.Configuration") 
     
        With cdoConfig.Fields 
            .Item(sch & "sendusing") = 2 ' cdoSendUsingPort 
            .Item(sch & "smtpserver") = "smtp.gmail.com" 
    		.Item(sch & "smtpauthenticate") = 1
    		'.Item(sch & "sendusername") = "rag84dec@gmail.com"
    		'.Item(sch & "sendpassword") =  "mypassword"
            .update 
        End With 
     
        Set cdoMessage = CreateObject("CDO.Message") 
     
        With cdoMessage 
            Set .Configuration = cdoConfig 
            .From = "rag84dec@gmail.com" 
            .To = "rag84dec@gmail.com" 
            .Subject = "Sample CDO Message" 
            .TextBody = "This is a test for CDO.message" 
            .Send 
        End With 
     
        Set cdoMessage = Nothing 
        Set cdoConfig = Nothing 
    
    					
    					%>
    
    Code (markup):
    getting the same error.... at the same line
    please help
     
    rag84dec, Apr 3, 2008 IP
  5. nubsii

    nubsii Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I just wrote this and successfully sent myself a message:

    
            MailMessage mailItem = new MailMessage();
            mailItem.To = "me@gmail.com";
            mailItem.Subject = "hi this is a test";
            mailItem.From = "me@gmail.com";
            mailItem.Body = "hi this is a test message";
            SmtpMail.SmtpServer = "smtp.gmail.com";
            mailItem.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);
            mailItem.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
            mailItem.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "me@gmail.com");
            mailItem.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "myPassword");
            mailItem.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
            SmtpMail.Send(mailItem);
    
    Code (markup):
    try maybe adding:
    
    .Item(sch & "smtpusessl") =  true //(or "true"? or 1?)
    
    Code (markup):
    let me know if that works for you

    goodluck
     
    nubsii, Apr 7, 2008 IP
  6. Amit_Jain

    Amit_Jain Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Try

    .Item(sch & "smtpusessl") = true //(or "true"? or 1?)

    I think ur problem should be solve by this
     
    Amit_Jain, Apr 10, 2008 IP
  7. salman4raza

    salman4raza Peon

    Messages:
    373
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    here is a simple solution in ASP. you can find fields of old form using request("formfield")
     
    salman4raza, Apr 24, 2008 IP
  8. jawahar

    jawahar Active Member

    Messages:
    1,044
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95