Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi Everyone,
i have a error in that Mail Coding,i try to send a Mail from aspx page using a Secure server but it provide a error while Uploading to a Server..
" the Error Is:"
Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

it is run in "Localhost" but not working in server..
i tried in many way.... here is my code...

and one more thing i have godaddy server.. Host:"secure server.net"
protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string str = null;
        str ="<table border='1'><tr><td>Email-ID:</td><td>" + txtEmailId.Text + "</td></tr><tr><td>Your Name:</td><td>" + txtname.Text + "</td><tr><td>Address:</td><td>" + txtaddress.Text + "</td></tr><tr><td>City:</td><td>" + txtcity.Text + "</td></tr><tr><td>State:</td><td>"+ txtstate.Text + "</td></tr><tr><td>Country:</td><td>" + txtcountry.Text + "</td></tr><tr><td>ZIPCode:</td><td>" + txtzipcode.Text + "</td></tr><tr><td>Phone No:</td><td>" + txtTelephoneNo.Text + "</td></tr><tr><td>Mobile No:</td><td>" + txtMobileNo.Text + "</td></tr><tr><td>Your Query:</td><td>" + txtYourQuery.Text + "</td></tr><tr><td>Your Comments:</td><td>" + txtComments.Text +"</td></tr></table>";

        Response.Write(SendMail("example@gmail.com", "example@mydomain.com", "mymail@gmail.com", "Welcome to my page", str));
        Response.Redirect("readex.aspx");
    }

    public string SendMail(string toList, string from, string ccList, string subject, string body)
    {



 System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
        SmtpClient smtpClient = new SmtpClient();
        string msg = string.Empty;
        try
        {
           
            MailAddress fromAddress = new MailAddress(from);
            message.From = fromAddress;
            message.To.Add(toList);
            if (ccList != null && ccList != string.Empty)
                message.CC.Add(ccList);
            message.Subject = subject;
            message.IsBodyHtml = true;
            message.Body = body;

           
            //smtpClient.Host = "smtpout.asia.secureserver.net";
            //smtpClient.Host = "smtpout.secureserver.net";
            smtpClient.Host = "relay-hosting.secureserver.net";
            //smtpClient.Port = Convert.ToInt32(emailServerInfo.MailServerPortNumber);
           // smtpClient.Port = 3535;
            smtpClient.Port = 25;
            //smtpClient.Port = 80;
            //smtpClient.Port = 465;
            smtpClient.UseDefaultCredentials = true;
           
            smtpClient.Credentials = new System.Net.NetworkCredential("example@mydomain.com", "mypassword");
            smtpClient.EnableSsl = false;
            //smtpClient.EnableSsl = true;
            smtpClient.Send(message);
            msg = "Successful";
        }
        catch (Exception ex)
        {
            msg = ex.Message;
        }
        return msg;


1.smtpClient.Host = "smtpout.asia.secureserver.net" this is only working in my localhost.. but it providing a error after uploading server..
2.relay-hosting.secureserver.net.... it not working in both localhost and also server..
3. smtpClient.EnableSsl = false; disable a ssl not working in localhost
smtpClient.EnableSsl = true; enable is working in local host...



above is my coding i want to know how to send a mail in my own domain name with smtp..
is any way to send that mail...? or what problem/Missed in my coding ?...please Answer ASAP...!!!
Posted

As it seem you don't have permission to send email. Please check the security level for your websites and sets it to a unrestricted set of permissions.

Try adding below line in the Web.Config for the web site:

HTML
<trust level="Full" originurl="" />


Hope this helps.
 
Share this answer
 
Comments
srigates 27-Jun-13 9:13am    
were it is placed in web config file.. i placed it in <system.net><mailsetting><smpthost> <trust level="Full" originurl="" />
but also not working
Please contact your hosting support. Certainly they they could help you with it. In Shared hosting, there are some restrictions in sending out mails. You could also use SmtpMail.SmtpServer, my hosting supports this way of sending out mail from asp.net applicaiton.

C#
SmtpMail.SmtpServer = "localhost";
string strTo = "<<to id>>";
string strFrom = "<<from id>>";
string strSubject = "subject";
string strMsgBody = "body";
SmtpMail.Send(strFrom, strTo, strSubject, strMsgBody);


Biju Joseph
http://just4sharing.com
 
Share this answer
 
Hi...
Can u see this, its may helpful to u.
C#
MailMessage myMail = new MailMessage();
            SmtpClient smtpclient = new SmtpClient();
            // mail fromaddress
            MailAddress fromadrress = new MailAddress("support mail id");
            myMail.From = fromadrress;
            //mail subject
            myMail.Subject = " RegisteredMail "+"Successfully";            

            string url = "" + HttpContext.Current.Request.Url.AbsoluteUri + "";
            myMail.IsBodyHtml = true;

            //mail body content
            myMail.Body = "some text";
            //mail toaddress             
                MailAddress Toadd = new MailAddress(textbox.Text);
                myMail.To.Add("" + Toadd + "");

                smtpclient.Host = "host mail id";
                smtpclient.Port = port no;
                smtpclient.Credentials = new system.Net.NetworkCredential "support mail id", "password");
                smtpclient.Send(myMail);

thank u.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900