Unable to send the mail

Hi,
I am new in meteor. I want send email but it is giving error. I have added the email package.
i have created account on the mailgun for the email services
I have button on main.html

Hello! I'm JobApp
 <button id="email1"> Test Email </button>

this is js code
’’'if(Meteor.isClient){
Template.HomeTemplate.events({

'click  #email1': function (e) {
  e.preventDefault();
  Meteor.call('sendEmail')
  
}

});

if(Meteor.isServer){
Meteor.methods({

‘sendEmail’:function(email,subj,body){
this.unblock();
alert(‘in the email function’)

  Email.send({

  to:'test@gmail.com',
  from:'no-reply@Meteordomail.com',
  subject:Test,
  text:'this is new mail'


  })


}

})
}```
It is not not enter in the if(meteor.isServer). and showing the error
"Error invoking Method ‘sendEmail’: Method ‘sendEmail’ not found [404]"

if I comment the meteor.isServer Condition then error shows
"Email is not defined"
and “Error invoking Method ‘sendEmail’: Method ‘sendEmail’ not found [404]”.

I moved the code in the Server folder but then it is showing
Error invoking Method ‘sendEmail’: Internal server error [500]

I have set process.env.MAIL_URL = “smtp://postmaster%40sandboxxxxxxxx.mailgun.org:xxxxxxxx@smtp.mailgun.org:587/”;

Can you please format your code by enclosing it in triple backticks:

```
like
this
```

Thanks :slight_smile:

if(Meteor.isClient){
Template.HomeTemplate.events({

       'click  #email1': function (e) {
        e.preventDefault();
        Meteor.call('sendEmail')

       }
  });
  if(Meteor.isServer){
    Meteor.methods({

  'sendEmail':function(email,subj,body){
    this.unblock();
   alert('in the email function')

    Email.send({

   to:'test@gmail.com',
  from:'no-reply@Meteordomail.com',
  subject:'Test',
  text:'this is new mail' })


 }
  })
 }

I have set process.env.MAIL_URL =
“smtp://postmaster%40sandboxxxxxxxx.mailgun.org:xxxxxxxx@smtp.mailgun.org:587/”;

is actually your method called correctly?
so check

  sendEmail(email,subj,body) {
       console.log(email)
    }

If you don’t get an output on your server console make sure that you import your method from server\main.js

server/main.js

import '../imports/api/email/email.js'

and your ‘…/imports/api/email/email.js’ should look like

import { Email } from 'meteor/email'
import {check } from 'meteor/check'

Meteor.methods({
    sendEmail(to, from, subject, text) {
        check([to, from, subject, text], [String]);

        this.unblock()

        Email.send({to, from, subject, text})
    }
})