Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

smtp switcher

10 views
Skip to first unread message

riyaz....@gmail.com

unread,
Nov 16, 2006, 12:01:58 AM11/16/06
to

hi.

i'm trying to make a tb extension that automatically switches the smtp
server depending on the ip address. the code given below works - any
ideas regarding the code r welcome.

now i'd like to make it more dynamic. include a dialog with which to
associate smtp servers with ip addresses. thinks: add a text file in
the smpt-settings dialog for entering ip addresses. hence when tb
starts, if any of the ip address pattern match the current ip addr
then that server is set as the default.

1) is this a good idea? shud i approach this differently? pitfalls?
2) any pointers to code that allows me to commandeer the smtp settings
dialog please?

cheers
riyaz


// get the ip address of this computer - only the first addr
var dnsService =
Components.classes["@mozilla.org/network/dns-service;1"].
getService(Components.interfaces.nsIDNSService);
var dnsRecord = dnsService.resolve(dnsService.myHostName, 0);
var ipAddress = dnsRecord.getNextAddrAsString();

// get/set smtp server
var smtpService =
Components.classes["@mozilla.org/messengercompose/smtp;1"].
getService(Components.interfaces.nsISmtpService);
var smtpServer = smtpService.getServerByKey("SMTP_SWITCHER_KEY");
// creates if not found
smtpService.defaultServer = smtpServer;

// match ipaddress and set smtp accordingly
var t = "192.100.100";
if (ipAddress.substring(0, t.length) == t) {
smtpServer.hostname = "smtp.server.com";
smtpServer.port = 25;
alert("found match");
}

0 new messages