I had this same problem with using my email account on the iPhone 4. I could receive email but it would give me " the server did not allow relaying" message. Initially, I had set up an aol account on my phone when I first got it because that's what I log into on my computer. What I had forgotten was that my email server is actually provided by netscape, but was merged with aol years back, I don't remember exactly when that happened but I think aol bought out netscape. Anyhow, this is what I did to work around it:
First, I deleted the aol email account from my phone.
Then, I logged into my email account through my computer. I went to the settings tab> IMAP and POP
There I found the IMAP set up information. (Keep this handy)
Next, On my iPhone: Settings> Mail,Contacts,Calendars> Add Account> Other> Add Mail Account
The user name, address, and password I entered was the same that I use to log in through my computer.
Finally, To complete the set up I used the IMAP set up information for incoming and outgoing mail servers. The set up took about 5 minutes. It worked with and without WiFi. I am using an iPhone 4 with the updated iOS5. It might even work with other email providers.
Please let me know if this helped.