Can I send email using javascript

后端 未结 6 1748
日久生厌
日久生厌 2021-01-04 09:11

Is it possible to send emails using just javascript?

相关标签:
6条回答
  • 2021-01-04 09:30

    EDIT: [WARNING!] README:

    It's a third party library that connects to an external server, take care with the information that you are sending.


    Another solution on JS you can use a library named smtpjs

    Add following library your html on header:

    <script src="https://smtpjs.com/smtp.js"></script>
    

    Use this without security:

    Email.send("from@you.com",
    "to@them.com",
    "This is a subject",
    "this is the body",
    "smtp.yourisp.com",
    "username",
    "password");
    

    Use this with security:

    Email.send("from@you.com",
    "to@them.com",
    "This is a subject",
    "this is the body",
    {token: "63cb3a19-2684-44fa-b76f-debf422d8b00"});
    
    0 讨论(0)
  • 2021-01-04 09:32

    It's actually possible and not all that difficult to build an SMTP client in Javascript.

    But that SMTP client will still need to talk to an SMTP server for getting its emails delivered. And SMTP servers open to everyone are very rare nowadays (because they quickly become Spam conduits and then blocked and/or closed).

    However, if the person using the client can supply an SMTP server and user credentials for it (just like with any other general purpose email client), then yes, you can send emails using just javascript.

    0 讨论(0)
  • 2021-01-04 09:32

    You can redirect to a mailto:someone@example.com?cc=someone_else@example.com&subject=This%20is%20the%20subject&body=This%20is%20the%20body address which tells the browser to fire up the mail client which then makes the mail ready to send - the user just has to hit "submit".

    Code:

    document.location="mailto:someone@example.com?cc=someone_else@example.com&"+
        "subject=This%20is%20the%20subject&body=This%20is%20the%20body";
    
    0 讨论(0)
  • 2021-01-04 09:38

    If you want to send the message "silently" from an SMTP process, then this needs to be done on the server or by using a hosted service.

    If you are happy to use the user's native email program, you could use an approach such as that described in this question.

    0 讨论(0)
  • 2021-01-04 09:42

    Note that smtpjs uses a service located at http://smtpjs. It's not truly a Javascript SMTP client. This "utility" means you are uploading your email credentials to the server smtpjs.com. Use with extreme caution.

    0 讨论(0)
  • 2021-01-04 09:48

    Yes. Using a Webservice. You can make an AJAX call to the service. EmailYak is one such service (It's in a private beta now).

    EDIT: This is still a server side solution, as the actual email is sent from the server. You are just communicating with a server via AJAX and telling it to send the email.

    0 讨论(0)
提交回复
热议问题