As I mention in my comment there are really several questions being asked. I will talk here a little bit about the port 25 issue.
Port 25 is the standard unencrypted SMTP port and it is quite common for system administrators to configure an organization's firewall to block outbound traffic on that port. This is done for two reasons primarily:
- To prevent malware, rogue software, spammers, etc. from sending email for nefarious
- To prevent legitimate users from sending email over an unencrypted channel.
The second one presumes that email sent over an encrypted connection (e.g. using SSL/TLS) is allowed by administrators for authorized users. The standard port for secure outbound SMTP is 587. If in your case this is allowed then that solves your problem. Establish an encrypted connection to your SMTP relay server over port 587. You will have to figure out how to do this in your code (or ask how separately/somewhere else).
Unfortunately, #1 often supersedes #2 and even secured email communications are not allowed by admins. If so, check whether your email provider (whoever mantains the SMTP relay) accepts traffic on alternate ports. For instance, some will give the option of using port 10025. Alternatively, there are third party email providers that can forward emails. That is they accept email on port 10025 and simply forward it to your primary provider's relay on port 25. Here's one example, first one my search turned up: "Alternate-port SMTP" service. This one has a fee. You may be able to find someone offering this for free (for low-volume, at least).
Or perhaps your administrator allows special exceptions to the policy. For instance, if you work for a company and demonstrate that the access is critical for the business they may allow the traffic on 25/587 for a limited number of originating hosts and/or for a specific SMTP relay address.
If you're still not successful then your next best bet is probably SSH tunnelling. You will need access to some machine outside of your firewall that runs an SSH server (e.g. sshd). Then you can set up a special kind of connection that listens on one port and forwards outbound to another port on another host somewhere. I won't go into the details of how to do this because there are already many descriptions online.
Update: I should add that if you use an alternate port or set up an SSH tunnel without discussing with your admin and they find out later there's a chance they may not look too kindly on it. If they're not happy you can kiss that option goodbye. On the other hand if you discuss it with them ahead of time they might forbid it outright. You'll have to weigh your options. As long as what you do does not negatively impact security a reasonable admin would be okay with it. They're not all reasonable, though. :)