Stop Email From Sending

2020-03-30 03:34发布

I am working on writing an add-on for Thunderbird and would like to be able to cancel the sending of an email under certain conditions. I have the following code which allows me to execute code before the email is sent, but I don't know how to stop it.

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 );

What do I need to do to stop the email?

1条回答
男人必须洒脱
2楼-- · 2020-03-30 04:28

In order to prevent the email from being sent you'd need to prevent the event from bubbling up:

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

window.addEventListener( "compose-send-message", send_event_handler, true );
查看更多
登录 后发表回答