6

Is it possible to add email notification triggers into a smart contract?

Could you store a persons email within a contract and at a set date have it send them an email?

2 Answers 2

4

Is it possible to add email notification triggers into a smart contract?

Not directly. You'd need a third party service that is watching the blockchain and then sends an email if it sees some condition happen. Alternatively, you could build such a service yourself. You'd need to be very careful your service isn't abused for spam floods. This is why such features weren't built into Ethereum from the start. (Probably best to mitigate the risk is by charging when an email is sent, similar to what Oraclize is doing.)

Could you store a persons email within a contract and at a set date have it send them an email?

Probably not the best idea to be storing people's email addresses within contracts. They will be world readable and not a good idea for long term planning. (Maybe you could tell the user what you're doing and let them accept the risk.) You're likely asking for a way to do person-to-person communication similar to a question I just asked yesterday: Will Whisper work with Ethereum contracts, or should I try another way for sending secrets?

1

Yes, you can use the blockchain2email.com API to send emails.

If you would like to schedule notifications at a set time, you can use the Oraclize API to call email sending. Here is an example:

import "dev.oraclize.it/api.sol";
contract blockchain2emailAPI {function SendEmail(string x, string y) returns(bool) {}}

contract Alarm is usingOraclize {

    function Alarm() {
       oraclize_query(1*day, "URL", "");
    }

    function SendEmail(string EmailAddress, string Message) internal returns (bool){
        return (blockchain2emailAPI(0xde5ebd0b8879b0a42b23b37e4d76a5e21a0bef4b).
            SendEmail.value(1000000000000000)(EmailAddress, Message));
    }

    function __callback(bytes32 myid, string result) {
        if (msg.sender != oraclize_cbAddress()) throw;
        SendEmail("[email protected]", "Your message goes here.");
    }

} 

However, as linagee mentioned, there is no privacy with this method, so be careful with publishing email addresses

1
  • As of 2021, blockchain2email.com is down Mar 9, 2021 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.