Flying-Toast / yugo

Yugo is an easy and high-level IMAP client library for Elixir.
https://hex.pm/packages/yugo
MIT License
42 stars 7 forks source link

No messages on Yandex IMAP #4

Closed sekrett closed 1 year ago

sekrett commented 1 year ago

Hello!

This is a great component. Receiving email messages as process messages is genius! Thank you. But I am receiving nothing from Yandex IMAP when real emails come. Is it Yandex specific or your component does not work? Can you name other services where it works? I tried wrong password, wrong mailbox intentionally, then I see error messages on console, so I think it is configured correctly when there are no errors on startup. I am not using any filters. Still no messages. The console is clean.

Flying-Toast commented 1 year ago

Thanks for reporting this. Could you post the relevant code you're using?

sekrett commented 1 year ago

Yes, sure:

defmodule BounceWatcher.Application do
  @moduledoc false

  use Application

  @impl true
  def start(_type, _args) do
    children = [
      {Yugo.Client,
        name: :imap_mm,
        server: "imap.yandex.ru",
        username: "...",
        password: "...",
        mailbox: "INBOX"}
    ]

    opts = [strategy: :one_for_one, name: BounceWatcher.Supervisor]
    Supervisor.start_link(children, opts)

    Yugo.subscribe(:imap_mm)

    receive do
      {:email, client, message} ->
        IO.inspect(client)
        IO.puts("Received an email with subject `#{message.subject}`:")
        IO.inspect(message)
    end
  end
end
Flying-Toast commented 1 year ago

Could you try with the latest git version (change your mix.exs dependencies to have {:yugo, git: "https://github.com/Flying-Toast/yugo.git", ref: "bdb9376"}) and let me know if it is fixed?

sekrett commented 1 year ago

Thanks, I updated and launched it again. Unfortunately still no reaction. mix.lock was updated appropriately.

Flying-Toast commented 1 year ago

Hmm, I am unable to reproduce this - I set up a yandex account and was able to receive messages using Yugo.

Here are a few more things I'd try:

Thanks for the info

sekrett commented 1 year ago

I have another Ruby script and I was able to fetch contents of old messages, so IMAP is enabled and password is correct. I can see the new email in web client, it's unread.

If it works for you, I will try to register another mailbox. In my mailbox I have a sorting rule which sends a copy to another email, leaving everything unread. It should not but maybe this is the cause of notifications being silenced. I will verify on a clean mailbox.

Flying-Toast commented 1 year ago

Are you leaving the yugo process running as the new emails arrive?

As it is written now, Yugo only watches for emails that arrive while yugo is running. I have not yet had a need to fetch previously-arrived emails, but I can look into implementing it if you have a use case.

sekrett commented 1 year ago

I know yugo will detect only new messages while running. Processing old messages is not a priority task now, there are already good clients in Ruby, Python and I will do that task just once.

Now I tried another mailbox without any rules configured, it detected the message but I got another error when trying to get the body:

:alex
Received an email with subject `kk`:

10:36:07.313 [notice] Application bounce_watcher exited: exited in: BounceWatcher.Application.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (Protocol.UndefinedError) protocol String.Chars not implemented for {"text/html", %{"charset" => "utf-8"}, "<div> </div><div> </div><div>.....</div><div> </div>\r\n"} of type Tuple. This protocol is implemented for the following type(s): Atom, BitString, Date, DateTime, Float, Hex.Solver.Assignment, Hex.Solver.Constraints.Empty, Hex.Solver.Constraints.Range, Hex.Solver.Constraints.Union, Hex.Solver.Incompatibility, Hex.Solver.PackageRange, Hex.Solver.Term, Integer, List, NaiveDateTime, Time, URI, Version, Version.Requirement
            (elixir 1.14.2) lib/string/chars.ex:3: String.Chars.impl_for!/1
            (elixir 1.14.2) lib/string/chars.ex:22: String.Chars.to_string/1
            (elixir 1.14.2) lib/io.ex:767: IO.puts/2
            (bounce_watcher 0.1.0) lib/bounce_watcher/application.ex:40: BounceWatcher.Application.start/2
            (kernel 8.5.2) application_master.erl:293: :application_master.start_it_old/4

Here is the updated receive block:

    receive do
      {:email, client, message} ->
        IO.inspect(client)
        IO.puts("Received an email with subject `#{message.subject}`:")
        IO.puts(message.body)
    end

The same on 0.3.0 and last commit on master.

sekrett commented 1 year ago

Sorry, now it is my fault. I need to learn how to work with processes. I managed to fix the error, but my application quits normally after first email comes. :)

Flying-Toast commented 1 year ago

Awesome, I'm glad you figured it out! Would you be able to share some more info about the mailbox rule you have set up? It sounds like it should still notify yugo, so I'd like to look into that :)

I think your application is crashing now because Application.start() is expected to return the value from Supervisor.start_link(), but here it is returning IO.inspect(message) - your Application shouldn't have any logic in it, just start the relevant processes and return. What you probably want is to create your own GenServer, that also gets started in your Application, and subscribes itself to the yugo client.

sekrett commented 1 year ago

The rule is simple: everything is being sent to another email and a copy is kept here. As I said the message after processing is marked unread, but the rule itself is the cause why IMAP is not sending notification. Another thing I noticed if I subscribe to Spam folder, also no messages are received, but the are no rules for spam.

I think I will examine this more and add a troubleshoot section to README. It is not obvious why this happens.

Thanks for hint on GenServer, that will probably work. My last attempt was:

    res = Supervisor.start_link(children, opts)
    Yugo.subscribe(:imap_mm)

    receive do
      ..
    end

    res

No errors but it quits. :)