This is the code I wrote:
MailMessage mail = new MailMessage("test@gmail.com", "me@myurl.com");
mail.Subject = "This is a test!!";
mail.Body = "testing...";
SmtpPermission connectAccess = new SmtpPermission(SmtpAccess.Connect);
System.Console.WriteLine("Access? " + connectAccess.Access);
SmtpClient client = new SmtpClient("mail.myurl.com", 2525);
client.Send(mail);
It's not working. I get an exception at the line "client.Send(mail)" that says "Mailbox unavailable. The server response was (MYLOCALCOMPUTERNAME) [MY LOCAL IP]:3045 is currently not permitted to relay through."
connectAccess.Access does return "Connect" (I'm not sure if this was necessary... I added it in to start the troubleshooting process.)
Does this mean that my local machine has to be configured in some way? What about when I deploy my app to other peoples machines? Will there need to be local configuration there? I'm just looking to create a "Send Feedback" type of link from my application.
(Note: in my real application I am using my real email addresses in both the "to" and "from" and my smtp is really my smtp address at the place that hosts my url/website)
thanks!
-Adeena
-
Is the destination address on the same host as your smtp server? If not, this would explain a relaying error.
The SMTP server you use needs to be either the final destination of the mail message or the first hop in the mail exchange. For example, if you're sending mail to a yahoo address from a gmail address, the first mail server to see the message must be your gmail server, or the yahoo server. Servers in between will reject the message because they have relaying disabled (to cut down on spam, etc.).
If they are the same host, are you able to send mail to it directly any other way?
Try this test via telnet to see if your smtp server is behaving properly: http://www.messagingtalk.org/content/470.html
-
@ Michael: thanks for the link. It's very helpful.
I think I figured out my problem. I did need to add the login credentials after I created my "client" object. I added the following line:
client.Credentials = new System.Net.NetworkCredential("myloginat+myurl.com", "mypassword");
(sorry - I have this habit that after I search for an answer on the web and through my manuals for 2 hrs, I finally break down and post the question and then 5 minutes later figure it out. :) I think the act of writing down the question helps me more than anything else)
So it's working... although I won't claim I understand everything about how and why it's working so I do expect to run in to some problems as I give my program to others to use. i.e., will everyone using the program that has an internet connection be able to open this smtp connection to my server? I don't know the answer to that... I'll have to wait, see, and learn some more.
Thanks! :)
-Adeena
configurator : Some SMTP servers require usernames and passwords - which is what you changed and solved the problem. Many SMTP servers, my ISP's for example, don't require passwords because they recognize the origin IP as coming from their ISP's subzone. -
I don't put my password in an application
-
Check your firewall. Is 2525 post open?
0 comments:
Post a Comment