停止发送电子邮件

时间:2012-09-20 01:18:45

标签: javascript thunderbird thunderbird-addon

我正在为Thunderbird编写附加组件,并希望能够在某些条件下取消发送电子邮件。我有以下代码,允许我在发送电子邮件之前执行代码,但我不知道如何阻止它。

document.getElementById("msgcomposeWindow").addEventListener( "compose-send-message", function(){
  var msgcomposeWindow = document.getElementById( "msgcomposeWindow" );
  var msg_type = msgcomposeWindow.getAttribute( "msgtype" );

  // do not continue unless this is an actual send event
  if( !(msg_type == nsIMsgCompDeliverMode.Now || msg_type == nsIMsgCompDeliverMode.Later) )
      return;


  alert('Sending Message...');//works fine
  if(true){ //eventually this would have more logic...
    //stop email
  }else{
    //let email go
  }
}, true );

停止发送电子邮件需要做什么?

1 个答案:

答案 0 :(得分:4)

为了防止发送电子邮件,您需要阻止事件冒泡:

function send_event_handler( evt ) {
    if(shouldStopEmail) {
        evt.preventDefault();
        return false;
    }
}

window.addEventListener( "compose-send-message", send_event_handler, true );