Gmail from address selector

By Brett Brotherton Last update Jun 26, 2007 — Installed 770 times.

Archived Comments (locked)

in
Subscribe to Archived Comments 5 posts, 4 voices



Jesse Andrews Admin

The following is an archive of comments made before threaded discussions was implemented (November 16th, 2008)

 
Du Song User

sorry for misformatted

var emailIndex = 1;
//-----------------------------------------------------------
// Check for certain email addresses
// this can be changed
// currently changes from address if emails are sent to a .edu email address
//-----------------------------------------------------------
var email_regex = "youku\.com";

document.addEventListener('click',function(event) {
 	if (event.target.tagName == 'BUTTON' && event.target.innerHTML == '<b>Send</b>') {
		var to = document.getElementsByName('to')[0].value;
		var cc = document.getElementsByName('cc')[0].value;
		var bcc = document.getElementsByName('bcc')[0].value;
		var from = document.getElementsByName('from')[0].value;
    //console.log('GMail from'+from+' to'+to);
		var myTest=new RegExp(email_regex);
		if(to.match(myTest) || cc.match(myTest) || bcc.match(myTest)){
			var frombox = document.getElementsByName('from')[0]
			frombox.selectedIndex = emailIndex;
 		}		
	}
}, true);

 
Du Song User

a *working* version for GMail 2.0

//-----------------------------------------------------------
// set this to index of email address you want to use
// index of 1 would select the second email in the drop down list
// index of 2 would select the third email in the drop down list and so on,
//-----------------------------------------------------------
var emailIndex = 1;
//-----------------------------------------------------------
// Check for certain email addresses
// this can be changed
// currently changes from address if emails are sent to a .edu email address
//-----------------------------------------------------------
var email_regex = "company\.com";

document.addEventListener('click',function(event) {
if (event.target.tagName == 'BUTTON' && event.target.innerHTML == 'Send') {
var to = document.getElementsByName('to')[0].value;
var cc = document.getElementsByName('cc')[0].value;
var bcc = document.getElementsByName('bcc')[0].value;
var from = document.getElementsByName('from')[0].value;
//console.log('GMail from'+from+' to'+to);
var myTest=new RegExp(email_regex);
if(to.match(myTest) || cc.match(myTest) || bcc.match(myTest)){
var frombox = document.getElementsByName('from')[0]
/*for (var i=0;i<frombox>
alert(frombox.options[i].value + ' ' + i);
}*/
frombox.selectedIndex = emailIndex;
//following line used for debugging the regular expression
//alert(frombox.length + ' ' + frombox.multiple + ' ' + frombox.options[2].value);
}
}
}, true);

 
jsheena User

This is very useful! I've made two modifications which I hope you'll find useful:

1. Now there's an array of address patterns

2. There's an optional user confirmation before changing the address.

Here's the code:

// ==UserScript==
// @name           Gmail from address selector
// @namespace      test123
// @description    Selects the from address of same domain your sending to
// @include        http*://mail.google.tld/mail/*
// ==/UserScript==



//-----------------------------------------------------------
// Check for certain email addresses
// this can be changed
// currently changes from address if emails are sent to a .edu email address
// You can add as many checks as you like by copying the line marked "copy this"
// 
// The first argument of the array is the regular expression matching email
// addresses you're sending to (or cc, or bcc).
// For example, ".*(mycompany.com).*" matches any address sent to mycompany.com
//
//
// The second argument of the array is the index of the email you want to use
// as the sender.
//
// set this to index of email address you want to use
// index of 1 would select the second email in the drop down list
// index of 2 would select the third email in the drop down list and so on,
//-----------------------------------------------------------


var emailMatchers = new Array (
	new Array(".*(.edu).*", 1),   /* <--><emailmatchers>

 
Brett Brothe... Script's Author

Oops fixed bug had commented out a line that was needed

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel