Sending email with ASP.NET in C#

Discussion in 'Free Hosting' started by wraithlunati, Jul 24, 2009.

Thread Status:
Not open for further replies.
  1. wraithlunati

    wraithlunati New Member

    I've been working on my website and I've run into a little snag.

    :Background Info:

    I'm hosted on lotus.x10hosting.com.
    I can send emails from outlook using both admin and noreply@blacktiesoft.co.cc to my gmail account no problem.
    I'm trying to setup a confirmation emailer so that users can be verified.

    :The Problem:

    I have tested the code on my local IIS server and I get an SmtpException stating the request timed out.
    Whenever I test the actual server, the page times out.
    In neither of these instances, the email gets sent.

    Here's the code from the hosted site:

    Code:
     
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Setup the client[/COLOR][/SIZE]
    [/COLOR][/SIZE]
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// I've tried lotus.x10hosting.com and mail.blacktiesoft.co.cc as well[/COLOR][/SIZE]
    [/COLOR][/SIZE]SmtpClient[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Client = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]SmtpClient[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"localhost"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], 465);[/SIZE]
    [SIZE=2]Client.EnableSsl = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]Client.UseDefaultCredentials = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]Client.Credentials = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]NetworkCredential[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([COLOR=#a31515]"noreply@blacktiesoft.co.cc"[/COLOR][SIZE=2], [/SIZE][/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"thepassword"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
     
    [SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Setup the message body...[/COLOR][/SIZE][/COLOR][/SIZE]
    String[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MessageBody = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// ..removed to save space[/COLOR][/SIZE][/COLOR][/SIZE][/SIZE]
     
    [SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]MailMessage[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Message = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]MailMessage[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"noreply@blacktiesoft.co.cc"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], Info.UserID, [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Account Confirmation"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], MessageBody);[/SIZE]
     
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]bool[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] failed = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]try[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2]{[/SIZE]
    [SIZE=2]Client.Send(Message);[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]catch[/COLOR][/SIZE]
    [/COLOR][/SIZE][SIZE=2]{[/SIZE]
    [SIZE=2]failed = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (failed == [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
    [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Save the Users Information[/COLOR][/SIZE]
    [/COLOR][/SIZE]
    
    I though I was doing all this by the book but for the life of me I can't understand why it would fail...

    Can someone shed some light on the subject? I've searched through the forums and haven't found any answers so I thought I fould finally ask.

    Dave
    Edit:
    http://forums.x10hosting.com/free-hosting/68233-sending-email.html <-- due to bad description of what works and what doesn't, I never tried the second recommendation, turns out, the second one works!

    To all those people that had this problem,

    The "by the book method", using the System.Net.Mail namespace doesn't work...

    The Method using the System.Web.Mail namespace worked like a charm!
    Last edited: Jul 24, 2009
Thread Status:
Not open for further replies.

Share This Page