Stop Email From Sending

一世执手 提交于 2019-12-30 11:34:28

问题


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:


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


来源:https://stackoverflow.com/questions/12504943/stop-email-from-sending

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!