Results 1 to 5 of 5

Thread: Sending mail with ASP.NET

  1. #1
    Bit Poster
    Join Date
    Sep 2011
    Posts
    3

    Default Sending mail with ASP.NET

    Hello,

    I want to send a confirmation mail to my users. I'm using ASP.NET MVC 2 and this is my code:

    var fromAddress = new MailAddress("admin@mydomain.com");
    var toAddress = new MailAddress("example@gmail.com");
    const string fromPassword = "xxxxxxxxx";
    string subject = "test";
    string body = "test text";
    var smtp = new SmtpClient
    {
    Host = "mail.mydomain.com",
    Port = 25,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Credentials = new NetworkCredential(<a user account with administrator role created in plesk>, <the user's password>)
    };
    using (var message = new MailMessage(fromAddress, toAddress)
    {
    Subject = subject,
    Body = body
    })
    {
    smtp.Send(message);
    }
    But I receive this exception when executing the above code:
    Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.
    Thanks in advance



  2. #2
    Parallels Team SvetlanaS's Avatar
    Join Date
    Sep 2011
    Posts
    110

    Default

    You have to authenticate to send an email. try this http://www.systemnetmail.com/faq/4.2.aspx



  3. #3
    Bit Poster
    Join Date
    Sep 2011
    Posts
    3

    Default

    I have authenticated as you can see in my code:

    Credentials = new NetworkCredential(<a user account with administrator role created in plesk>, <the user's password>)



  4. #4
    Parallels Team SvetlanaS's Avatar
    Join Date
    Sep 2011
    Posts
    110

    Default

    What kind of mail Server used by SmtpClient class?
    You are able to switch to this mail server: Home>Tools & Settings>Server Components>Select default Webmail component
    Last edited by SvetlanaS; Sep 22, 2011 at 03:36 AM.



  5. #5
    Bit Poster
    Join Date
    Sep 2011
    Posts
    3

    Default

    Thank you for your help. The problem was in the settings of the SMTP server. It was configured to deny relay from any incoming IP!
    I've found the solution here



Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •