-1

I am using smtp.js to send mails to my email id whose credentials i made using smtp.js.I made a contact form where i want the user to enter his info and email and that should be sent to my email.So according to this logic, my mail should be in To property and sender's mail should be in the From property.However, when i run the code, it throws an error as "Mailbox name not allowed. The server response was: Envelope FROM 'sendername@gmail.com' email address not allowed.". If not possible,can u tell me some other alternative using js.Thanks Code:

function sendmail()
    {
    
            var name = $('#name').val();
            var email = $('#email').val();
            var phone = $('#phone').val();
            var address = $('#address').val();
            var postal = $('#postal').val();
            console.log(typeof(email))
            // var body = $('#body').val();

            var Body='Subject: '+"Estimated Quote"+'<br>Name: '+name+'<br>Email: '+email+'<br>Phone: '+phone+'<br>Address: '+address+'<br>Postal Code: '+postal+'<br>Quote exl VAT: '+vat_excl+'<br>Quote incl VAT: '+vat_incl;
            //console.log(name, phone, email, message);

            Email.send({
                SecureToken:"2d019ac3-046b-4c4f-94e2-f4f3bf08fb1f",
                To: 'receivermail@gmail.com',
                From: email,
                Subject: "New mail from "+name,
                Body: Body
            }).then(
                message =>{
                    console.log (message);
                    if(message=='OK'){
                    alert('Thanks for submitting details.We will contact you soon.');
                    }
                    else{
                        console.error (message);
                        alert('Error submitting form.')
                        
                    

}

prog_24
  • 771
  • 1
  • 12
  • 26
Saad Ali
  • 1
  • 2
  • 1
    This might be related to your SMTP config, are you aware that accepts the email address that you're sending to? – SaC-SeBaS Jul 02 '22 at 19:16
  • I did some research and found out that authorized email from smtp should be used in From property which does not make sense.Why would i put my own email in From property when i need it to receieve emails from senders. – Saad Ali Jul 02 '22 at 19:21
  • Do you know any other 3rd party library in js. – Saad Ali Jul 02 '22 at 19:23
  • check my answer, I'd suggest you to use nodemailer – SaC-SeBaS Jul 02 '22 at 19:26
  • 1
    @SaC-SeBaS — There are plenty of email protocols which cause mail to be marked as spam is the From address doesn't match the server being used to send the email. Your server is being used to send the email. It should be marked as being from your email address. I would be surprised if smtp.js let you send email from an unverified address. – Quentin Jul 02 '22 at 19:33
  • I’m voting to close this question because Stack Overflow is for *programming* topics; questions about email deliverability are off-topic here. See also https://meta.stackoverflow.com/questions/302903/off-topic-my-email-isnt-spam – tripleee Jul 05 '22 at 08:39

2 Answers2

1

This error you are running into is a security feature. If you think about it, you shouldn't be able to make it appear as if someone else has sent an email (there is a lot of malicious potential in that).

Because of that, I'm not sure whether other SMTP providers would get you much further. I personally am using SmtpJS for my project and this is a code snippet of how I made it work for my needs:

Email.send({
        SecureToken : "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", // The secure token of the registered smtpJS email
        To : 'test@test.com', // The email that the ticket will be sent to (it can be any email)
        From : "test@test.com", // Must be a registered smtpJS email
        Subject :  subject, // Should have a(n) (ideally unique) random ticket number appended to a common subject title
        Body : "Name: " + fullname.value // This would be derived from the form
            + "<br> Email: " + email.value // This would be derived from the form
            + "<br> Phone: " + phone.value // This would be derived from the form
            + "<br> Message: " + message.value // This would be derived from the form
    }).then(
        message => alert(message)
    );

Best of luck!

Pranai Rao
  • 113
  • 2
0

I don't know which library are you using to stablish the SMTP connection, but first of all make sure that the SMTP sever accepts all the domains that you're requiring.

I'd suggest you to use nodemailer which is fairly easy to use.

Example:

// CONFIG SETUP
import { createTransport } from 'nodemailer';

const Transporter = createTransport({
  host: process.env.SMTP_HOST || 'localhost',
  port: Number(process.env.SMTP_PORT) || 25,
  secure: false,
  tls: { rejectUnauthorized: false }, // THIS WILL BE ACCORDING TO YOUR SMTP CONFIG
});

// EXAMPLE OF USAGE
const info = Transporter.sendMail({
      from: 'sender@test.com',
      to: 'to@test.com',
      subject: 'TEST',
      text: 'TEST',
    });
SaC-SeBaS
  • 174
  • 8
  • 1
    "I don't know which library are you using to stablish the SMTP connection" — They are using the client-side SMTP.js library (as they said in the question) and a third-party web-service to connect to their SMTP server. There's no suggestion that they are using Node.js (or have access to any form of server-side programming). – Quentin Jul 02 '22 at 19:34
  • Nodemailer is for nodejs apps.I am using plain js. Can @Quentin suggest any 3rd part library. – Saad Ali Jul 02 '22 at 19:58
  • As the problem is server-side, switching to a different client is unlikely to provide any benefits. – tripleee Jul 05 '22 at 08:35