+ Reply to Thread
Results 1 to 5 of 5

Thread: Email, ASP.NET amd authentication

  1. #1
    thegriff is offline x10Hosting Member thegriff is an unknown quantity at this point
    Join Date
    Sep 2009
    Posts
    14

    Question Email, ASP.NET amd authentication

    I have set up a system where registration and login are required, and as part of teh registration process I confirm Email addresses by sending a message containing an authorization code - all pretty standard stuff.

    The problem is that the only way I have found to send the email needs my cpanel login id and password, which I don't want to include in the ASP.NET code, or even in the web.config file if I can help it. Is there some authentication I have missed which doesn't use this?

    Code:
    System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
    string body = "Hello " + mu.UserName + " and thank you for registering your new account...<br/>";
    mail.Body = body;
    mail.IsBodyHtml = true;
    mail.To.Add(newMailAddress(mu.Email));
    mail.From = new System.Net.Mail.MailAddress("NoReply@XXX.x10hosting.com", "NoReply@XXX.x10hosting.com", Encoding.UTF8);
    mail.Subject = "New account registration";
    mail.SubjectEncoding = Encoding.UTF8;
    mail.Priority = System.Net.Mail.MailPriority.High;
    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
    smtp.Host = "mail.XXX.x10hosting.com";
    smtp.Port = 26;
    smtp.Credentials = new System.Net.NetworkCredential("<my log in id>", "<my log in password>");
    smtp.Send(mail);
    No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.


    FOR SALE: Bargain! Large supply of slightly used '0's and '1's. Can be delivered electronically. Special rates for bulk purchases!

  2. #2
    ah-blabla's Avatar
    ah-blabla is offline x10 Lieutenant ah-blabla is an unknown quantity at this point
    Join Date
    Sep 2009
    Posts
    375

    Re: Email, ASP.NET amd authentication

    If you were using php you could use the sendmail() function, and I think I have found an ASP equivalent here, which uses something called CDOSYS.
    Last edited by ah-blabla; 10-27-2009 at 06:27 AM.

  3. #3
    srikri is offline x10Hosting Member srikri is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    10

    Re: Email, ASP.NET amd authentication

    Hi thegriff,

    Your code looks fine... I don't think there is any way you can bypass smtp authentication in asp.net. If you are not comfortable in including password in code or web.config, use php (only to send mail). Below is the php code for sending mail.

    <?php
    $sendTo = "xxx@xxx.x10hosting.com";
    $subject = "Your subject goes here";
    $headers = "From: <your mail id>";
    $message = "testing";
    mail($sendTo, $subject, $message, $headers);
    ?>

  4. #4
    ah-blabla's Avatar
    ah-blabla is offline x10 Lieutenant ah-blabla is an unknown quantity at this point
    Join Date
    Sep 2009
    Posts
    375

    Re: Email, ASP.NET amd authentication

    Quote Originally Posted by srikri View Post
    Your code looks fine... I don't think there is any way you can bypass smtp authentication in asp.net.
    You can though:
    Code:
    <%
    Set myMail=CreateObject("CDO.Message")
    myMail.Subject="Sending email with CDO"
    myMail.From="mymail@mydomain.com"
    myMail.To="someone@somedomain.com"
    myMail.TextBody="This is a message."
    myMail.Send
    set myMail=nothing
    %>
    (From the w3schools link in my earlier post.)
    I'm just not sure whether it will work here since X10 uses Mono. I would recommend you use php generally though since that is a much more common language.
    Last edited by ah-blabla; 10-27-2009 at 10:11 AM.

  5. #5
    thegriff is offline x10Hosting Member thegriff is an unknown quantity at this point
    Join Date
    Sep 2009
    Posts
    14

    Re: Email, ASP.NET amd authentication [SOLVED]

    Thank you for the replies - I have found a solution!

    The Authentication requirement is a red herring; simply remove all reference to it and the problem goes away. The following code sends a email to a user (of the standard ASP.NET membership system):
    Code:
    
    ///<summary>
    /// Send an email to the user.
    ///</summary>
    ///<param name="mu">User to send email to</param>
    ///<param name="body">Text to send</param>
    ///<param name="subject">Seubject line</param>
    ///<param name="from">Subaccount to send from. If null or empty, NoReply will be used.</param>
    publicstaticvoid SendUserEmail(MembershipUser mu, string body, string subject, string from)
    {
    if (string.IsNullOrEmpty(from))
    {
    from = "NoReply";
    }
    try
    {
    MailMessage mail = newMailMessage();
    mail.Body = body;
    mail.IsBodyHtml = true;
    mail.To.Add(newMailAddress(mu.Email));
    mail.From = newMailAddress(from + strEmailAccountBase, from + strEmailAccountBase, Encoding.UTF8);
    mail.Subject = subject;
    mail.SubjectEncoding = Encoding.UTF8;
    mail.Priority = MailPriority.Normal;
    SmtpClient smtp = newSmtpClient();
    smtp.Host = "mail.XXX.x10hosting.com";
    smtp.Port = 26;
    smtp.Send(mail);
    }
    catch (Exception ex)
    {
    thrownewApplicationException("Could not send email", ex);
    }
    }
    
    No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.


    FOR SALE: Bargain! Large supply of slightly used '0's and '1's. Can be delivered electronically. Special rates for bulk purchases!

+ Reply to Thread

Similar Threads

  1. How to get ASP.Net to work at x10Hosting
    By Hue Kares in forum Tutorials
    Replies: 56
    Last Post: 11-11-2011, 01:09 PM
  2. Profiting from “Unsolicited Email Marketing”
    By arkad in forum Earning Money
    Replies: 0
    Last Post: 11-17-2008, 11:43 PM
  3. Email Authentication
    By Mohron in forum Free Hosting
    Replies: 2
    Last Post: 07-10-2008, 10:29 PM
  4. What is Authentication
    By asadislam78 in forum Computers & Technology
    Replies: 1
    Last Post: 12-13-2007, 07:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers