Page view counter

Problem with System.Net.Mail on GoDaddy

Last post 04-22-2009 7:12 PM by ScriptStudios. 33 replies.

Sort Posts:

  • Crying [:'(] Problem with System.Net.Mail on GoDaddy

    11-23-2005, 4:45 AM
    • Loading...
    • eddie_mcsd_uk
    • Joined on 08-09-2002, 2:47 PM
    • Posts 8
    • Points 30

    Last night after a bit of "fun and games" I managed to get my website http://www.alex-parks.org/ upgraded to .NET Framework 2.0 on GoDaddy.  And generally I'm happy.

    Unfortunately though sending emails using System.Net.Mail doesn't work, so the site can't send out emails when people register etc.  Obviously this has to be addressed.

    At the moment I have "smtpout.secureserver.net" with port 80 set on the SMTPClient object (I have to set *something* or there is an error message that says SMTP server is not specified), and the error message I get is

    "Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

    On .NET 1.1 I didn't have to set the SMTP details, it just "worked".  If anyone knows how to get this to work on GoDaddy it'd be much appreciated, I can't believe I'm the only one.

    Many thanks

  • Re: Problem with System.Net.Mail on GoDaddy

    11-23-2005, 2:57 PM
    • Loading...
    • eddie_mcsd_uk
    • Joined on 08-09-2002, 2:47 PM
    • Posts 8
    • Points 30
    Just thought I would update to say that I've gone back to System.Web.Mail for the time being.

    Fortunately this still seems to work, despite the warnings the compiler gives about obsolescence. 

    Normally I have Option Strict On which had stopped my web app compiling because of the use of System.Web.Mail.

    However, after loosening the compiler it's now OK.  But I look upon this as a short term solution and I'd still appreciate any answer to get it working with System.Net.Mail.


  • Re: Problem with System.Net.Mail on GoDaddy

    11-29-2005, 2:43 PM
    • Loading...
    • jjstreic
    • Joined on 04-28-2004, 2:09 AM
    • Madison Wisconsin
    • Posts 507
    • Points 2,535
    I'm not a VB person but looking at the MSDN documentation for this
    http://msdn2.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx

    I would guess that your host and port properties are not set correctly.  Just a guess based on the port 80 referenced above (SMTP runs over TCP/25)

    Below is an excerpt from MSDN on the SmtpClient call.

    To construct and send an e-mail message by using SmtpClient, you must specify the following information:

    • The SMTP host server that you use to send e-mail. See the Host and Portproperties.

    • Credentials for authentication, if required by the SMTP server. See the Credentials property.

    • The e-mail address of the sender. See the Send and SendAsync methods that take a from parameter. Also see the MailMessage.From property.

    • The e-mail address or addresses of the recipients. See the Send and SendAsync methods that take a recipient parameter. Also see the MailMessage.To property.

    • The message content. See the Send and SendAsync methods that take a body parameter. Also see the MailMessage.Body property.

    Technical Account Manager
    Microsoft Communication Sector North America
    This posting is provided "AS IS" with no warranties, and confers no rights. Script samples are subject to the terms at http://www.microsoft.com/info/cpyright.htm"
  • Re: Problem with System.Net.Mail on GoDaddy

    12-05-2005, 12:34 PM
    Answer
    • Loading...
    • eddie_mcsd_uk
    • Joined on 08-09-2002, 2:47 PM
    • Posts 8
    • Points 30
    Posting again to say I have found the solution !  Smile

    After doing more Googling around, it seems that smtpout.secureserver.net was not the correct outgoing server to use, since using this comes back with error messages such as "Mailbox name not allowed" and "not allowed in the list of rctphosts" and such.

    The answer is to use an alternative called relay-hosting.secureserver.net.  Therefore the code below below should work for you as it now does for me :-

    Dim objMailMessage As New System.Net.Mail.MailMessage

    With objMailMessage
        .IsBodyHtml = False
        .From = New MailAddress("fromaddress@youremailaccount.com")  
        .To.Add("destinationaddress@whoever.com") .Subject = "Your Subject"
        .Body = "Body Text"
    End With

    Dim objSMTPClient As New System.Net.Mail.SmtpClient("relay-hosting.secureserver.net", 25) objSMTPClient.Credentials = CredentialCache.DefaultNetworkCredentials objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.Network objSMTPClient.Send(objMailMessage)

  • Re: Problem with System.Net.Mail on GoDaddy

    12-07-2005, 3:19 PM
    • Loading...
    • jjstreic
    • Joined on 04-28-2004, 2:09 AM
    • Madison Wisconsin
    • Posts 507
    • Points 2,535

    I'm very glad you found a resolution to the problem.  Many thanks for posting back with your solution!

     

    Technical Account Manager
    Microsoft Communication Sector North America
    This posting is provided "AS IS" with no warranties, and confers no rights. Script samples are subject to the terms at http://www.microsoft.com/info/cpyright.htm"
  • Re: Problem with System.Net.Mail on GoDaddy

    12-07-2005, 5:29 PM
    • Loading...
    • Blake05
    • Joined on 12-02-2005, 11:22 PM
    • Wisconsin
    • Posts 501
    • Points 2,498
    The solution was nice but I moved to c#. :S I gotta go find a c# version did you find any good sites for this. They cant be that hard to google. Just wondering in your search if you found anything worth while.
  • Re: Problem with System.Net.Mail on GoDaddy

    01-29-2006, 11:55 PM
    • Loading...
    • stasevich
    • Joined on 07-04-2002, 2:45 PM
    • Posts 6
    • Points 15

    I am having the same issue.
    Trying to send mail with .NET.MAIL via GODADDY.COm SMTP relay service.

    My code still gives me the same error:

    Mailbox name not allowed. The server response was: sorry, relaying denied from your location [my IP ADDRESS] (#5.7.1)
     
    as I am not sure what to put there or how to setup credentials with goDaddy server, I bet this is my problem.
    So if anyone could point me to the right direction how to user Credentials, that would be great.
     
    I commented this line though:
    objSMTPClient.Credentials = CredentialCache.DefaultNetworkCredentials
     
     
     
    as I am not sure what to put there or how to setup credentials with goDaddy server, I bet this is my problem.
    So if anyone could point me to the right direction how to user Credentials, that would be great.
     
    Did you have to put EXACT email address that you have setup for relay wih GODADDY, is that how they authenicate you?
  • Re: Problem with System.Net.Mail on GoDaddy

    01-30-2006, 4:34 AM

    Hello,

    Check the following from my hosting KB

    Note: You should have POP email/pass with godaddy

     

    Regards

  • Re: Problem with System.Net.Mail on GoDaddy

    01-30-2006, 11:12 AM
    • Loading...
    • stasevich
    • Joined on 07-04-2002, 2:45 PM
    • Posts 6
    • Points 15

    Yes, I figured out how to use Credentials last night. I specified account that i created for SMTP relay, i even tried passing my domain as a 3rd optional parameter, still get the error that host is not allowed.
    I think godaddy support rep hates me by now, for asking so many questions, but they have been very quick to respond as of today.
    I host my site locally, so i am wondering if maybe i need to change some setting in IIS, but i belive setting defaultdeliverymethod=network should avoid going trough my local virtual smtp server.

  • Re: Problem with System.Net.Mail on GoDaddy

    03-15-2006, 6:04 PM
    • Loading...
    • tdritzema
    • Joined on 03-15-2006, 11:02 PM
    • Posts 1
    • Points 5
    There is one facet of GoDaddy that is somewhat annoying. They make you turn on SMTP email relaying and by default limit you to like 250 outgoing relays per day. You might want to check on your GoDaddy settings to make sure it's enabled.
  • Re: Problem with System.Net.Mail on GoDaddy

    03-23-2006, 4:53 AM
    • Loading...
    • sdi126
    • Joined on 01-22-2006, 9:25 PM
    • Posts 5
    • Points 12

    I also have godaddy as my hosting and have found that I did not need to use the line of code about credentials.  It was working all along for me....I was not getting any errors but found that the test email  addresses I was filling into my form where being sent to my spam folder thats why I was not seeing them.  Below is my code that works hosted with godaddy:

    Private Sub SendMail(ByVal from As String, ByVal body As String)

    Dim mailServerName As String = "relay-hosting.secureserver.net"

    Dim message As MailMessage = New MailMessage(from, "youremail@host.com", "", body)

    Dim mailClient As SmtpClient = New Smtpclient

    mailClient.Host = mailServerName

    mailClient.Port = 25

    message.Subject = "comments from my site"

    message.Body = body

    mailClient.Send(message)

    message.Dispose()

    End Sub

    web dev | http://arizonawebdevelopment.com
    free wifi | http://localwifisearch.com
  • Re: Problem with System.Net.Mail on GoDaddy

    03-25-2006, 1:46 PM
    • Loading...
    • yair01
    • Joined on 03-25-2006, 6:31 PM
    • Posts 2
    • Points 10
    I had the same problem with "relaying denied from your location" and solved it by adding "auth login":

    I have a free email account on a regitered godaddy domain let's call it myaccount@mydomain.com
    myaccount is configured to allow SMTP relaying (not sure if needed) and I am _not_ using system.net.mail but instead a C# Mailer Example (http://www.aspemporium.com/) that uses sockets directly. You need to use "myaccount@mydomain.com" as the username and the same password used when loggin on the godaddy web-based mail.

    here is the code:

            void SendMail()
            {
                //create and send a simple email with no attachments/
                //without using System.Web.Mail

                //this will be achieved in three steps.
                // 1.) generate an RFC compliant email
                // 2.) establish a connection to email server using sockets
                // 3.) send mail using SMTP

                //generate an RFC compliant email
                ///////////////////////////////////////////
                DateTime d = DateTime.Now;

                //abbrevWeekday, day abbrevMonth year hour:minute:second timeZoneOffset
                string rfcDate = d.ToString("ddd, d MMM yyyy H:m:s zz00");

                //build the email as a gigantic string
                StringWriter sw = new StringWriter();
                //headers...

                sw.WriteLine("Subject: subject line");
                sw.WriteLine("To: recipient <recipient@yahoo.com>");
                sw.WriteLine("From: sender <sender@yahoo.com>");
                sw.WriteLine("Date: " + rfcDate);
                sw.WriteLine("Content-Type: text/plain");
                sw.WriteLine("X-Mailer: C# Mailer Example (http://www.aspemporium.com/)");
                sw.WriteLine();
                //body...
                sw.WriteLine("Body");
                sw.Flush();
                //store email as string for later on
                string email = sw.ToString();
                sw.Close();
                sw = null;

                //establish a connection to email server using sockets
                ///////////////////////////////////////////
                string smtpServer = "smtpout.secureserver.net";
                int smtpPort = 25;

                TcpClient client = null;
               
                try
                {
                    //create connection to mail server
                    client = new TcpClient(smtpServer, smtpPort);
                    NetworkStream ns = client.GetStream();
                    StreamReader stdIn = new StreamReader(ns);
                    StreamWriter stdOut = new StreamWriter(ns);

                    //send email with SMTP
                    ///////////////////////////////////////////

                    //SERVER GREETING
                    int responseCode = GetResponse(stdIn);
                    if (responseCode != 220)
                        throw new Exception("no smtp server at "+
                            "specified address or smtp server not ready");

                    //HELO COMMAND
                    stdOut.WriteLine("HELO " + Dns.GetHostName());
                    stdOut.Flush();
                    responseCode = GetResponse(stdIn);
                    if (responseCode != 250)
                        throw new Exception("helo fails. code="+responseCode);

                    stdOut.WriteLine("auth login");
                    stdOut.Flush();
                    responseCode = GetResponse(stdIn);
                    if (responseCode != 334)
                        throw new Exception("auth login. code="+responseCode);

                    stdOut.WriteLine(Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes("myaccount@mydomain.com")));
                    stdOut.Flush();
                    responseCode = GetResponse(stdIn);
                    if (responseCode != 334)
                        throw new Exception("username. code="+responseCode);

                    stdOut.WriteLine(Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes("mypassword")));
                    stdOut.Flush();
                    responseCode = GetResponse(stdIn);
                    if (responseCode != 235)
                        throw new Exception("password. code="+responseCode);

                    //MAIL COMMAND
                    stdOut.WriteLine("MAIL FROM:<sender@yahoo.com>");
                    stdOut.Flush();
                    responseCode = GetResponse(stdIn);
                    if (responseCode != 250)
                        throw new Exception("FROM email considered bad by server. "+
                            "code="+responseCode);

                    //RCPT COMMAND - first email
                    stdOut.WriteLine("RCPT TO:<recipient@yahoo.com>");
                    stdOut.Flush();
                    responseCode = GetResponse(stdIn);
                    switch(responseCode)
                    {
                        case 250:
                        case 251:
                            break;
                        default:
                            throw new Exception("TO email considered bad by server. "+
                                "code="+responseCode);
                    }

                    //DATA COMMAND
                    stdOut.WriteLine("DATA");
                    stdOut.Flush();
                    responseCode = GetResponse(stdIn);
                    if (responseCode != 354)
                        throw new Exception("data command not accepted. "+
                            "code="+responseCode);
                    //send email that was generated before
                    stdOut.WriteLine(email);
                    stdOut.Flush();
                    //send . on a line by itself to signify end of stream
                    stdOut.WriteLine(".");
                    stdOut.Flush();
                    responseCode = GetResponse(stdIn);
                    if (responseCode != 250)
                        throw new Exception("email not accepted. "+
                            "code="+responseCode);

                    //QUIT COMMAND
                    stdOut.WriteLine("QUIT");
                    stdOut.Flush();
                    responseCode = GetResponse(stdIn);
                    if (responseCode != 221)
                    {
                        //who cares
                    }

                    Console.WriteLine("SUCCESS: mail accepted for delivery!");

                }
                catch(Exception ex)
                {
                    Console.WriteLine("ERROR: " + ex.Message);
                }
                finally
                {
                    //dont forget to close that socket...
                    if (client != null)
                        client.Close();
                    client = null;
                }
            }

            int GetResponse(StreamReader stdIn)
            {
                try
                {
                    string response = "";
                    //keep reading until no more response because
                    //some commands in SMTP return more than one
                    //line
                    do
                        response += stdIn.ReadLine()+"\r\n";
                    while(stdIn.Peek() != -1);

                    //print the response to the console just for fun
                    Console.WriteLine(response);

                    //get the three digit smtp code returned by the server
                    return Convert.ToInt32(response.Substring(0, 3));
                }
                catch
                {
                    //catch any errors
                    return 0;
                }
            }

  • Re: Problem with System.Net.Mail on GoDaddy

    10-20-2006, 11:10 AM
    • Loading...
    • mkpro17
    • Joined on 05-30-2006, 1:20 AM
    • Cherry Hill
    • Posts 4
    • Points 14

    I had somewhat the same types of issues using godaddy dedicated and Virtual dedicated hosting. Go Daddy Does not allow the use of port 25 unless it is used through their relay servers. In my case I have a corporate exchange environment in-house and I keep some simple web enviroments at godaddy.

    So I needed my program to send email, however I wanted it to be sent using one of my exchange servers in-house.

    Since Go daddy is blocking port 25 I was unable to get my smtp client to connect to my in-house exchange server. So I decided to bend the rules, I configured my exchange server with a second smtp port of 587 and set my smtp client to use that prot when sending the email.

    Viola!.. works like a charm, here is a c# code example if that helps you understand.

    --

    mathew@seamlessdev.com

    www.SeamlessDev.com

     

    // EXAMPLE

    MailMessage objEmail = new MailMessage();

    objEmail.To.Add("sales@yourwebsite.com");

    objEmail.From = new MailAddress("info@yourwebsite.com");

    objEmail.Subject = "Email from yourwebsite.com";

    objEmail.Body = "<table cellspacing='0' cellpadding='0' border='1' bordercolor='#000000'><tr><td bgcolor='#CCCCCC'>" + "YOUR MESSAGE HERE" + "</td></tr></table>";

    objEmail.IsBodyHtml = true;

    try

    {

    SmtpClient smtp = new SmtpClient("exmail.domainname.com", 587);

    smtp.Credentials = new NetworkCredential("userid", "password", "DOMAIN");

    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

    smtp.Send(objEmail);

    }

    catch (Exception err)

    {

         Response.Write("Email Send Failed, Please Try again<br />" + err.Message);

         return;

    }

    Mathew
    www.SeamlessDev.com
    So Simple, So Perfect, So... Seamless!
  • Re: Problem with System.Net.Mail on GoDaddy

    12-09-2006, 9:00 PM
    • Loading...
    • porov
    • Joined on 02-01-2006, 8:39 PM
    • Posts 59
    • Points 187
    I like godaddy for my domains but i would not like to use them for my hosting for reason such as this, i use webhost4life.com they are great.
    Free Web Hosting - My asp.net website
  • Re: Problem with System.Net.Mail on GoDaddy

    01-19-2007, 11:53 AM
    • Loading...
    • Zelda55
    • Joined on 01-19-2007, 3:13 PM
    • Posts 17
    • Points 2

    Me too.  Very tired of trying to resolve this issue.  Any words of wisdom?  I've tried using different port numbers.  I've tried using different host names/strings.  I've tried miles and miles of code.  Currently using some code I picked up somewhere in this forum called MailHelper.  Also, forgive me if this is a totally stupid question, but in the Web.config file I included my username and password.  Isn't that a big security no-no?  What's protecting that info?

     Anyway...  here's my Web.config mail settings:

    <

    mailSettings>

    <

    smtp from="me@mydomain.com">

    <

    network host="relay-hosting.secureserver.net" port="3535" userName="me@mydomain.com" password="*******"/>

    </

    smtp>

    </

    mailSettings>

    This code is in my App_Code folder:

    Imports

    System.Net.Mail

    Public

    Class MailHelper

    ''' <summary>

    ''' Sends an mail message

    ''' </summary>

    ''' <param name="from">Sender address</param>

    ''' <param name="recipient">Recipient address</param>

    ''' <param name="bcc">Bcc recipient</param>

    ''' <param name="cc">Cc recipient</param>

    ''' <param name="subject">Subject of mail message</param>

    ''' <param name="body">Body of mail message</param>

    Public Shared Sub SendMailMessage(ByVal from As String, ByVal recipient As String, _

    ByVal subject As String, ByVal body As String)

    ' Instantiate a new instance of MailMessage

    Dim mMailMessage As New MailMessage()

    ' Set the sender address of the mail message

    mMailMessage.From =

    New MailAddress(from)

    ' Set the recepient address of the mail message

    mMailMessage.To.Add(

    New MailAddress(recipient))

    ' Check if the bcc value is null or an empty string

    'If Not bcc Is Nothing And bcc <> String.Empty Then

    ' ' Set the Bcc address of the mail message

    ' mMailMessage.Bcc.Add(New MailAddress(bcc))

    ' End If

    ' Check if the cc value is null or an empty value

    'If Not cc Is Nothing And cc <> String.Empty Then

    ' ' Set the CC address of the mail message

    ' mMailMessage.CC.Add(New MailAddress(cc))

    ' End If

    ' Set the subject of the mail message

    mMailMessage.Subject = subject

    ' Set the body of the mail message

    mMailMessage.Body = body

    ' Secify the format of the body as HTML

    mMailMessage.IsBodyHtml =

    True

    ' Set the priority of the mail message to normal

    mMailMessage.Priority = MailPriority.Normal

    ' Instantiate a new instance of SmtpClient

    Dim mSmtpClient As New SmtpClient()

     

    ' Send the mail message

    mSmtpClient.Send(mMailMessage)

    End Sub

    End

    Class

     

    And this is the vb that makes the button work that's supposed to send the mail:

    Imports

    system.net.mail

    Partial

    Class SendMail7

    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

    MailHelper.SendMailMessage(

    "me@mydomain.com", "me@mydomain.com", "Sample Subject", "Sample body of text for mail message")

    End Sub

    End

    Class

     

    '''''''''''''''''''''''''''''''''

    I end up with an SMPTException, Failure to send mail, Inner Exception, bla, bla, bla...

     

    Someone, anyone?  Please help me?

     

Page 1 of 3 (34 items) 1 2 3 Next >