Send email automatically by java Mail API android without intent - on background

Поділитися
Вставка
  • Опубліковано 19 вер 2024
  • Today, I’m going to show you how to send email from android app using java mail API. Watch to learn how it work and don’t forget to turn on your notifications!
    First you need to create app password for send email from app.Follow the instructions.
    Create & use App Passwords
    Go to your Google Account.
    On the left navigation panel, choose Security.
    On the "Signing in to Google" panel, choose App Passwords. If you don’t see this option:
    2-Step Verification is not set up for your account.
    2-Step Verification is set up for security keys only.
    Your account is through work, school, or other organization.
    You’ve turned on Advanced Protection for your account.
    At the bottom, choose Select app and choose the app you’re using.
    Choose Select device and choose the device you’re using.
    Choose Generate.
    Follow the instructions to enter the App Password. The App Password is the 16-character code in the yellow bar on your device.
    Choose Done.
    source code on gitHub :
    github.com/Usa...
    download lib :
    code.google.co...

КОМЕНТАРІ • 54

  • @chalso0
    @chalso0 2 роки тому

    If Anyone has problems with Transport.send, the problem is with the google's permissions, you must put a aplication password. Great Video!

  • @LykosMenon
    @LykosMenon 2 роки тому

    I love you for this, man. Really saved my ass. I don't know why SMTP servers are so needlessly annoying to set up, but they really are. Your code is so much cleaner than basically all other solutions I found AND yours actually works straight away, no fuss. props, man.
    Worth noting for others in the future, it didn't work in the emulator and I was lost for a while on why it wouldn't work, but for the sake of seeing if the emulator was causing issues, I loaded it on my phone and boom, the message was sent.

  • @technotutorials4412
    @technotutorials4412 2 роки тому

    brother i am sad that why didn't i found your video first, good work keep it up

  • @emanmohsen4135
    @emanmohsen4135 7 місяців тому

    Thank you so much, i wish i found this perfect source before all that wasted time,
    If I may ask, how can i attach a file to this mail please ???

  • @RafaelPereira-rm1rl
    @RafaelPereira-rm1rl 4 роки тому

    Congrats man, this actually helped me a lot, I'll share it alright bro.

  • @lucianobrandao6217
    @lucianobrandao6217 3 роки тому

    Nice.... helped me a lot, where did u learn this? i could not find document about

  • @anasssbai293
    @anasssbai293 3 роки тому +1

    Thanks a lot it helped me so much,but is there anyway to send some html code with the page?

  • @yamsani735
    @yamsani735 3 роки тому

    Thanks a lot. This works like a charm...

  • @geminisk3678
    @geminisk3678 4 роки тому +1

    Perfect !, I have a problem with the login video. How could I contact you to consult a thing ...?

    • @runtimecode4058
      @runtimecode4058  4 роки тому +1

      Send me your LinkedIn or Facebook account and i will connect with you ... Thx 👍😊

    • @geminisk3678
      @geminisk3678 4 роки тому

      @@runtimecode4058 thanks! facebook.com/kevin.geminis.7/

  • @souvikmaity3362
    @souvikmaity3362 Рік тому +1

    this doesn't work anymore

  • @dipeshvaghela3329
    @dipeshvaghela3329 3 роки тому +1

    when i have use my personal email in utils.java it does not work but when i have use yours it works. what security i have to change in my personal email??

    • @computersecurityduniya3900
      @computersecurityduniya3900 3 роки тому

      go to your google account and turn on
      Go to your Google Account.
      On the left navigation panel, choose Security.
      On the "Signing into Google" panel, choose App Passwords. If you don’t see this option:
      2-Step Verification is not set up for your account.
      2-Step Verification is set up for security keys only.
      Your account is through work, school, or other organizations.
      You’ve turned on Advanced Protection for your account.
      At the bottom, choose Select app and choose the app you’re using.
      Choose Select device and choose the device you’re using.
      Choose Generate.
      Follow the instructions to enter the App Password. The App Password is the 16-character code in the yellow bar on your device.
      Choose Done.

  • @maliha.ishtiaq
    @maliha.ishtiaq 3 роки тому +1

    but in my case. it is not sending email from my app.

  • @gta-servicesgta-services7396
    @gta-servicesgta-services7396 3 роки тому +1

    hi there,
    good job perfect.
    and can you explain how can i add a attachment in the mail ?
    thx a lot.

    • @computersecurityduniya3900
      @computersecurityduniya3900 3 роки тому +1

      yes i will show you

    • @computersecurityduniya3900
      @computersecurityduniya3900 3 роки тому

      MimeMessage msg = new MimeMessage(session);
      try {
      msg.setFrom(new InternetAddress(Utils.EMAIL));
      msg.addRecipients(Message.RecipientType.TO, String.valueOf(new InternetAddress(toEmail)));
      msg.setSubject("Csv Files ");
      //msg.setText("This is automatic mail form text android");
      Multipart emailContent = new MimeMultipart();
      MimeBodyPart textbody = new MimeBodyPart();
      //textbody.setText("Test msg");
      //csv attachment
      MimeBodyPart pdfAttachment = new MimeBodyPart();
      Calendar c = Calendar.getInstance();
      int day, month, year, hr, min, sec;
      String date, time;
      day = c.get(Calendar.DAY_OF_MONTH);
      month = c.get(Calendar.MONTH);
      year = c.get(Calendar.YEAR);
      hr = c.get(Calendar.HOUR_OF_DAY);
      min = c.get(Calendar.MINUTE);
      sec = c.get(Calendar.SECOND);
      time = hr + "-" + min + "-" + sec;
      date = day + "-" + month + "-" + year + "-" + time;
      String folder_main = "Sensor_Data";
      String csv = (Environment.getExternalStorageDirectory().getAbsolutePath() +"/"+folder_main+"/"+"sensor_data.csv");
      pdfAttachment.attachFile(csv);
      emailContent.addBodyPart(textbody);
      textbody.setText(date);
      emailContent.addBodyPart(pdfAttachment);
      msg.setContent(emailContent);
      Transport.send(msg);
      } catch (MessagingException e) {
      e.printStackTrace();
      } catch (IOException e) {
      Toast.makeText(context, "Error while sending file", Toast.LENGTH_SHORT).show();
      e.printStackTrace();
      }
      here is the working code
      you can change the path as you need and it will send the document to the current time date and millisecond

    • @computersecurityduniya3900
      @computersecurityduniya3900 3 роки тому

      for msg.addRecipients(Message.RecipientType.TO, String.valueOf(new InternetAddress(toEmail)));
      this line variable define your destination email address into String for Example
      String toEmail= "example232@gmail.com";

    • @gta-servicesgta-services7396
      @gta-servicesgta-services7396 3 роки тому

      thanks but i already have it.

    • @emanmohsen4135
      @emanmohsen4135 7 місяців тому

      ​@@gta-servicesgta-services7396could you please tell me how to attach file to this email?

  • @glr2130
    @glr2130 2 роки тому

    I'm not able to add the loibs folder in project structure, after adding the files in libs I can't open them in project structure, can you help me please?

  • @HaiNguyenVan-kw3hn
    @HaiNguyenVan-kw3hn Рік тому

    I can't send a message to Mail , I think since the K app can access the account in the Ultils class, can u help me ? thank u verry much

  • @isaackaranja9802
    @isaackaranja9802 3 роки тому

    Thanks...works fine.

  • @nurmaizurah6349
    @nurmaizurah6349 3 роки тому +2

    is it possible to send image as an attachment, if yea can u tell me how?

  • @cappahemployee4426
    @cappahemployee4426 4 роки тому +1

    It's not working for me

  • @spk4426
    @spk4426 3 роки тому +1

    Bro, now this code throws no error. But I'm not receiving the mail sent from app.

  • @sanju_baba_2
    @sanju_baba_2 Рік тому

    Can you use one image with the text please

  • @GurmeetSingh-zq3br
    @GurmeetSingh-zq3br 3 роки тому

    Thanks bro

  • @someshgusain2707
    @someshgusain2707 4 роки тому

    Is this work on the fragment tab as i created navigation drawer and i wanted to send the mail from the fragment can you please help

  • @alexialosadaifors9012
    @alexialosadaifors9012 2 роки тому

    With the new google update, from 31st of May 2022 you will need to login with a application password (can generate these in your mail account settings), if not the authentication will result as failed

    • @sergibordes8401
      @sergibordes8401 2 роки тому

      Can you explain it? I have the same problem and I don't know how to fix it...

    • @____9827
      @____9827 2 роки тому

      @@sergibordes8401 try using this password instead of using the acconut password support.google.com/accounts/answer/185833?hl=en

  • @maliha.ishtiaq
    @maliha.ishtiaq 3 роки тому

    hey @Runtime Code. can you please help me in how to use app password for an android emulator?

  • @akshata4092
    @akshata4092 3 роки тому

    thank you : )

  • @klotzekehrt6938
    @klotzekehrt6938 3 роки тому

    Cannot resolve symbol 'context'

  • @chris7085
    @chris7085 Рік тому

    4:04 u do it so fast are u in a hurry

    • @chris7085
      @chris7085 Рік тому

      Error in .getDefaultInstance() how to fix it?!

  • @maliha.ishtiaq
    @maliha.ishtiaq 3 роки тому

    please help me.

  • @fur1us556
    @fur1us556 3 роки тому

    Hi, i want to use this code to send a specific message to an email every time someone presses the button. Is there any way to make the string for mail,subject and message to be fixed?

    • @LykosMenon
      @LykosMenon 2 роки тому +1

      I'm sure it's a tad late for you now, but in MainActivity, you can change the variables in private void senEmail() to be something like String mMessage = "Sample Message Body"; and that should do it.

    • @fur1us556
      @fur1us556 2 роки тому

      @@LykosMenon Well I finished the project at work by now, but still thanks your replying !

    • @urvinsavla4571
      @urvinsavla4571 2 роки тому +1

      @@LykosMenon Thanks

  • @harishbariya3463
    @harishbariya3463 4 роки тому

    it's free

  • @osamasrour1105
    @osamasrour1105 Рік тому

    I try and I install the source code but I face below :
    javax.mail.AuthenticationFailedException
    Any help plz

  • @mattiacaldognetto8110
    @mattiacaldognetto8110 2 роки тому

    where i can contact you for a help?