nsForum logo

Welcome Guest ( Log In )

 
Reply to this topicStart new topic
> Asp.net Email Sending Error
shayeb
post Nov 10 2011, 12:28 PM
Post #1





Group: Verified NS Member
Posts: 7
Joined: 31-August 11
Member No.: 15,153



I get this error when I try to send email by code:
{Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.}

the problem is with the port number as in medium trust level you can't use other port than 25
but I'm trying to use the email from my hosting package on networksolutions and it give the smpt ports 2525 or 587

any advice



here is the code maybe it will help

MailMessage mail = new MailMessage();
mail.To.Add(Email);
mail.From = new MailAddress("PasswordRecovery@metraininghub.com");// sender mail
mail.Subject = "metraininghub.com Password Recovery";

mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.metraininghub.com";
//smtp.Host = "localhost";
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = false;

smtp.Credentials = new NetworkCredential
("PasswordRecovery@metraininghub.com", "*****************");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = CredentialCache.DefaultNetworkCredentials;
smtp.Port = 2525;
smtp.Send(mail);





I also tried puting it on the webconfig file but gave a simliar error because of the port too
here is what I wrote on webconfig

<mailSettings>
<smtp from="PasswordRecovery@metraininghub.com">
<network host="smtp.metraininghub.com" port="587" userName="PasswordRecovery@metraininghub.com"
password="****************" defaultCredentials="false"/>
</smtp>
</mailSettings>
Go to the top of the page
 
+Quote Post
Craig
post Nov 10 2011, 12:35 PM
Post #2





Group: Administrators
Posts: 827
Joined: 23-June 08
From: Pennsylvania
Member No.: 1,317



QUOTE (shayeb @ Nov 10 2011, 01:28 PM) *
I get this error when I try to send email by code:
{Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.}

the problem is with the port number as in medium trust level you can't use other port than 25
but I'm trying to use the email from my hosting package on networksolutions and it give the smpt ports 2525 or 587

any advice



here is the code maybe it will help

MailMessage mail = new MailMessage();
mail.To.Add(Email);
mail.From = new MailAddress("PasswordRecovery@metraininghub.com");// sender mail
mail.Subject = "metraininghub.com Password Recovery";

mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.metraininghub.com";
//smtp.Host = "localhost";
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = false;

smtp.Credentials = new NetworkCredential
("PasswordRecovery@metraininghub.com", "*****************");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = CredentialCache.DefaultNetworkCredentials;
smtp.Port = 2525;
smtp.Send(mail);





I also tried puting it on the webconfig file but gave a simliar error because of the port too
here is what I wrote on webconfig

<mailSettings>
<smtp from="PasswordRecovery@metraininghub.com">
<network host="smtp.metraininghub.com" port="587" userName="PasswordRecovery@metraininghub.com"
password="****************" defaultCredentials="false"/>
</smtp>
</mailSettings>


You need to use "localhost" as the SMTP server on port 25. The user and password should be blank. The hosting firewall does not allow connections fo an external SMTP server. Our nsMail and nsHosting services run on different servers.
Go to the top of the page
 
+Quote Post
shayeb
post Nov 10 2011, 01:02 PM
Post #3





Group: Verified NS Member
Posts: 7
Joined: 31-August 11
Member No.: 15,153



with code?

or with webconfig?
Go to the top of the page
 
+Quote Post
shayeb
post Nov 10 2011, 01:14 PM
Post #4





Group: Verified NS Member
Posts: 7
Joined: 31-August 11
Member No.: 15,153



I trieded with both
and it gives a new error

Object reference not set to an instance of an object.



SmtpClient smtp = new SmtpClient();
smtp.Host = "localhost";
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

MailMessage mail = new MailMessage();
mail.To.Add(Email);
mail.From = new MailAddress("PasswordRecovery@metraininghub.com");// sender mail
mail.Subject = "metraininghub.com Password Recovery";

mail.Body = Body;
mail.IsBodyHtml = true;

//smtp.Port = 25;

smtp.Send(mail);



<mailSettings>
<smtp from="PasswordRecovery@metraininghub.com">
<network host="localhost" defaultCredentials="false"/>
</smtp>
</mailSettings>
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
Tags
No Tag inserted yet

1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version    Network Solutions © 2011 Time is now: 31st October 2014 - 05:56 AM
Domain Names | Web Hosting | Web Design | Shopping Cart Software | Online Marketing | SSL Certificates