Which mail service to choose. Collecting mail from different mailboxes on one Gmail account

Switching from one tab with Gmail to another with Yandex.Mail is quite tedious. And if you have a dozen accounts with different email providers, checking new correspondence in the morning turns into torture. By combining letters in one place, you will get rid of this inconvenience.

Web interface

Most email providers provide a built-in feature for collecting emails from multiple mailboxes. For example, let's try to collect letters from all your mailboxes in one Gmail account.

First of all, make sure that the postal service from which you want to pick up letters has POP access. Then go to your Gmail settings and click Settings in the top right corner. Go to the “Accounts” tab and look for the “Receive mail from other accounts” section.

Add an account, enter your email address and click Next, then enter your password. To make mail exchange between providers more secure, make sure that the “Always use a secure connection (SSL) when receiving mail” option is enabled. Then click on “Add account”.

Now letters arriving at the added address will be automatically collected in the Inbox of your Gmail. You can add as many mailing addresses as you need.

Desktop clients

Email needs software. Yes, you can do a lot in the web mail client (sometimes much more than Google currently allows you to do in Gmail). But the web interface cannot be compared with a native application. Even the most modern Web UI is a bottleneck when working with mail.

Rafe Needleman, Сnet.com

Desktop email clients are good because they can aggregate emails from multiple accounts. At the same time, you can work with dozens of addresses and not even think about which provider stores this or that message.

Most desktop email clients have a built-in shared Inbox. Even if your favorite client only supports individual inboxes, you can still easily bring them together using smart filters.

Even though Outlook is designed to manage multiple mailboxes at once, it still displays a separate Inbox for each account. But this can be easily fixed using filters.

Open Outlook, go to the Folders tab and click New Search Folder on the toolbar. Then select "Create a custom search folder." Click Select, but do not select any search criteria, so that all new messages are sent to the folder. Name the folder anything you like, for example “All Mail”.

Click on “Browse”, select all the folders and mailboxes from which you want to collect mail, and check the “Search in subfolders” option.

Now the smart folder you created will contain emails from all the email accounts you added to Outlook. You can enable the “Show in Favorites” option so that your new mail is always visible.

The Mac email client provides a single inbox for all connected accounts. Just add your accounts, and all new letters will be collected in one place.

In Thunderbird, collecting all your emails in one inbox is easy. Go to the View menu (if the menu bar is not displayed, press Alt). Then select “Folders” → “Merged”. You will now have one Inbox for new emails, one Drafts folder, one Sent Items folder, and one Archive folder. You won't have to look for long to find out what's where. In this case, messages will, as before, be stored on the servers of your mail providers.

Mobile clients

Unified Inbox is available in many mobile email clients, including Gmail. The Gmail app collects your inbox from all email accounts, including Yahoo, Outlook, or other services.

If you don't like Google's app, you can try third-party email clients such as Outlook or MyMail.

Maybe you have your own ideas on how to group mail in one place? Share in the comments.

Instructions

Log in to your account by following the following link http://gmail.com and entering your username and password.

Click the gear icon in the top right corner of Accounts & Import. Then go to the “Send emails as” block and click on the “Add another email address of yours” link.

In the new window that pops up, enter the first and last name to which the added e-mail is registered, as well as the e-mail address. Click on the “Next Stage” button.

Next, a request will appear on the screen asking how to send letters when using this address - using the Gmail service or the mail interface from QIP. It is advisable to specify Gmail; there are fewer settings, therefore, less time will be spent. Click on the "Next Action" button.

The next window notifies you that after clicking the “Send Confirmation” button, you will need to check the specified e-mail so that Gmail is sure that the e-mail address actually exists. Click the button and open your mailbox in a new tab.

Review your unread emails and open the email with the title “Gmail Confirmation.” Click the link to confirm the existence of this email address, or copy the code.

If you copied the code, paste it into the empty field of the "Add another..." window and click the "Verify" button. After some time, this window will automatically close and a new e-mail will appear in the “Send emails as” list.

Now, in the same way as described, you need to add a new address to the “Collect mail from other accounts” block. To do this, click the “Add your POP3 email account” link.

In the new window that pops up, enter your email address. Click on the "Next Action" button. In the next window, you must enter a password and activate the options “Always use a secure connection” and “Assign a label to incoming emails.” Then click the “Add account” button. After some time, this window will automatically close and a new e-mail will appear in the “Collect mail from other accounts” list.

E-mail has become an integral part of the lives of users on the Internet. There are many resources that provide a mailbox. Often you need to check existence box, its reliability. If you need to find out about the authenticity of an email address, then there is nothing difficult about it.

Instructions

Register an email address with the same name if you are interested in an email created on some free resource. A previously existing email cannot be registered again. All known mail servers are provided with a return notification system. In this case, you will receive an error notification indicating that further registration is impossible.

Try writing a letter from an email address available to you. box to the desired e-mail. The message can be with or without text. Send it and check your e-mail after some time for received letters. If you were notified that your letter did not reach the desired address, then this mail may not exist.

Register in the “My World” network. This is a social network on the RuNet in which many users communicate. Use the search for other users' accounts. Enter the desired e-mail in the search bar, which is located in the right corner at the top of the site page. You can click on the “People” button. You will be taken to a search for accounts based on various criteria. Just enter the e-mail you are interested in in the field that you will find called “Search”. You must click “Find”. If the mailing address is correct, you will see information about the owner of the mail.

If you have mailboxes on other email services, set up a mail collector so that all the information is in one place.

For the collector to work correctly, you must configure it only under your Mail.Ru account. Make sure you are logged into your Mail.Ru account before you start collecting emails from other email services.

To add a box:

  1. Click on the logo of the service where your box is located. If your service is not in the list, click “Other mail”.
  2. Enter the mailbox name and password, click “Add”. If you see an error message, check that the data you entered is correct and try again. If the data is entered correctly, you will receive a confirmation and can continue setting up the mail collector.

Depending on which protocol is supported by the service on which the mailbox is located, the settings may differ:

IMAP

  1. Specify which folder you want to move emails to and click “Save.”
  2. If you have personal folders in the mailbox from which you will collect mail, they will be nested in the selected folder.

System folders are also synchronized: “Drafts”, “Sent Items”, “Spam” and “Trash”. If you will be importing emails from a third-party mailbox into your Inbox, specify whether you want to apply the filters configured in the current mailbox to incoming emails.

If the collection of letters is configured using the IMAP protocol, you will be able to respond to letters from the mailbox to which the letter was sent.

POP3

  1. Check the “All mail” checkbox to import all messages from the mailbox. If you want to mark all imported emails as read, check the “Mark all old emails as read” checkbox.
  2. Select which folder you want to place emails from this mailbox. If you want to create a new folder, check the box next to the drop-down list and enter the name of the folder.
  3. To apply filters that are configured in the mailbox to messages from other servers, check the box next to “Apply filters to received messages.”
  4. Click "Save".

This way you can specify up to 9 mailboxes from which letters will be collected. To disable the mail collector, set the switch to the OFF position. If you want to edit the settings, click "Edit". To remove the faucet, click Remove.

This article will talk about what “mail from other mailboxes” and “collecting letters from other accounts” are. Email service reviews and comparisons.

As we update the functionality of email services, we will publish news at the end of this article.

The mail service Mail.ru, search engines Yandex and Google have been offering very useful and necessary functionality for several years now, which allows you to combine all other e-mail accounts in one mail. In other words, you just need to add and configure all your “mails” once, and it will be possible to manage them in one window without constantly entering your login and password.

Mail services offer us a huge space for storing all incoming letters, a convenient interface, good management functionality and much more. To test the capabilities of the listed email services, we will highlight three parameters to evaluate their performance: 1) it is necessary to manage various e-mail accounts, including from various services and sites, through one email client; 2) have a personal signature and name for each mail; 3) delete letters from the servers of those mail accounts that were added to mail, yandex or google mail.

Our task looks like this:

So let's get started. The first to test is the service from Mail.ru, which tells us: “You can collect mail from all your mailboxes into one mailbox on Mail.ru.

Set up the collection of letters from any server running the IMAP or POP3 protocol." To add external mail other than @mail, @inbox, @list, @bk, you need to have at least one mail that already exists on the listed servers from mail. In other words, register your mail first, and then add other mail accounts. The process of registering for mail is simple, there is no point in describing it, but we will describe adding other e-mails to this mail account.


Next, you will be asked to enter the login and password for any mailbox you use, and within 3-5 minutes, the “Mail Collector from mail” will create a folder with the name of the added mail next to the “inbox”, “sent”, “spam” and other.


In fact, the letter collector will work within 10-15 minutes and will add all letters to the newly created folder from the mailbox you specified. All incoming letters for the new e-mail will be sent to this folder, and it will also be possible to send letters from the attached mailbox. When creating a new letter, the “From” field will appear, in which you can select from which mailbox the letter will be sent.


The advantages of the Mail.ru mail service include the ease of adding and ease of setting up other mailboxes, and the absence of the need to specify different protocols (POP3, SMTP). This is very important because not every user knows what it is.

The disadvantages of Mail.ru are that it is impossible to assign a name and signature for each newly added mail (any new e-mail except the main one), that is, the name and signature of the main mail will apply to each address and that’s it. Another big drawback is that when uploading letters to mail, there is no way to automatically delete the original letters from the attached mailbox server. Why is it so important to delete emails from the server of an added mailbox? This will avoid filling out the attached mail, because... External email accounts are usually too small to store emails. For example, if the mail space in your external account is full, Mail.ru will not display any new messages until you enter the external mail interface and delete messages directly from there to free up space. In addition, we link mail to Mail in the hope of getting a lot of storage space for our mail, which may be limited by hosting resources. Thus, despite the fact that Mail.ru offers almost unlimited mailbox capacity, when adding mail from another domain zone (for example, ), your added e-mail resources will not increase in Mail.ru, but will continue to be limited by resources hosting (in our case, primer.ru resources).

The ability to add another mail to the Mail service did not satisfy our task on two points out of three, with a total of one point.


True, Mail.ru has another way to add external mail, or more precisely, connect or log in to external mail. It looks like this:


This method is not suitable for our task, because This is not a mail collector, but a user mode that connects to mail and loads all folders and letters into the mail interface every time. But here it is possible to add a personal signature and name for each mail, it is possible to send letters from the configured mail. Deleting emails from loaded mailboxes does not work because... This is not a mail collector.

Important! Some users mistakenly think that if letters are displayed in mail, then the mail from which the download occurred can be cleared. Let us note once again that Mail.ru works as a mail viewer, and if you clear your mail, it will be deleted both in the main mailbox and in mail.

The second test subject is Yandex with his letter collector. The tasks are similar: collect mail, assign a signature and name to each mail, and also delete all mail from the added mailbox.

The Yandex mail collector is configured according to a similar scheme, but if mail is connected from some site, for example site.ru, then additional settings will need to be specified, see screenshot.


The Mail service did this work for us, but Yandex offers to manually set all the settings from third-party mail. There is nothing complicated here: in the login field we enter the full name of the mail (), in the server field we enter only the domain (site.ru), it is better to leave all other settings as default, or change them if you know what you are doing. After successfully adding mail, the following message will appear:


Unlike the Mail collector, Yandex offers you to choose whether to save the original letters in the added mailbox or not. In all other respects, the letter collector from Yandex works in a similar way to Mail.ru; you can select the mailbox from which to send the letter. But Yandex has the same problem with signing letters: it is not possible to set an individual name and signature for each added mailbox.


Judging by the navigation, it is possible to add an individual signature for each mailbox, but in reality it does not work. Select your email, enter your name and signature, and click save. That's it, the signature is saved and works, but it is also saved for all other mailboxes, that is, by assigning a name and signature to one mailbox, you automatically change these parameters in all mail combined in Yandex. Even if you select any other box, the signature will now be the same everywhere.

In total, Yandex has successfully coped with the collection and sorting of mail, it can delete original letters from the added mailbox, but it cannot work with signatures! The Yandex email collector failed to cope with our task and scores two points out of three.


I would like to note that, having delved into all three services for assembling letters, it seems that Mail has whipped up its functionality. Although it will satisfy most users, to be honest, Mail made a mail collector for show, to show off in the competitive race. Everything works well and without failures, but the collector from Mail could not cope with our task. The mail interface has several advertising blocks, but they do not interfere with working with letters.

As for Yandex, which created a mail collector a long time ago, it seems that this particular industry is not being supported, because fixing such a simple functionality (the ability to add multiple signatures for mailboxes) should not be difficult for such a powerful search engine. However, Yandex has added another unique functionality that allows you to link domains to their DNS servers, and subsequently create and configure mail. But such operations and settings require knowledge and time. And although there is nothing complicated there, in any case, it is not for most RuNet users. Great advantage- no advertising in the Yandex mail interface! Minus- limit in the letter collector to 10 mailboxes.

The finalist and winner is a letter collector from Google, which coped with our task with a bang, despite 5 box limit

The other day, the next version of Mail.Ru Mail was released for iPhone and iPad. The main update is one, but significant: it is the ability to collect all the user’s mailboxes in one place, namely in the Mail.Ru Mail application.

All mail in one place. Most of us have several emails - for work, for registering on various forums, coupon sites and online stores, and for the soul (read - for communicating with friends, relatives, etc.). In the previous version of the Mail.Ru application, the developers took the first step towards streamlining the management of the “zoo” of accounts: they added support for multiple mailboxes.

Now, in the Mail.Ru Mail client, you can work not only with mailboxes on this service, but also with accounts of Gmail, Rambler, Outlook and other providers that support IMAP/POP3. Switching between boxes is very simple - it's a matter of one click. While a user is viewing one account, others are patiently waiting for their turn.

The application does not rearrange the order in different boxes in its own way. In each of the accounts, you can continue to follow exactly the logic of work to which you have become accustomed. For example, in the interface of the Mail.Ru application, the names and structure of folders, checkboxes and other mailbox settings on Gmail will remain the same as in the large version of Gmail. In addition, in the application you can individually configure each of the accounts: set a signature, enable or disable the display of icons, configure the operation of the push notification system.


Push notifications. Advanced push notifications deserve special mention. Firstly (and this is one of the main bonuses of the application), they can be enabled even for accounts on those services that cannot send pushes.

Secondly, they can be configured exactly as you wish, specifying in detail what time they should arrive and what to report. It is possible to mark by name the recipients whose messages you are willing to read day and night (for example, letters from your mother), or strictly from 9 to 19:00 (most likely, these will be letters from clients or colleagues). You can turn alerts on or off for specific accounts, folders, or recipients.

The developers carefully provided a button that allows you to immediately disable notifications about mailings from social networks or coupon services. You can also set the content of push notifications: you may want to hide the recipient's name or subject line for privacy reasons.

Quick actions. For convenient work with letters, the application has a quick action menu. To call up these magical buttons, you just need to swipe from right to left on the desired message in the list of letters. With their help, you can delete a letter, check a box, move it to another folder, send it to spam, etc. All actions are performed in one click.

Avatars of recipients and services will help you navigate your mail. They are visible in the list of letters, when reading and writing letters, and, as already mentioned, in push notifications. When reading and writing a letter, the user sees an avatar of the sender or recipient, as well as a preview of attachments. If photographs or drawings are attached, thumbnails of the images are displayed. By the way, you can view attachments without leaving the cash register, i.e. right in the app.

Caching. Caching will be very useful in places where the Internet is not very good, for example, in the subway. The owner of a smartphone with the Mail.Ru email client will be able to read texts and view photos even in the absence of a network.

Hints. The application prompts you for the desired email, you should enter the first letters in the address bar (provided that you have written to this recipient at least once - it does not matter whether in the main version of Mail or in the application). In addition, the client, at your request, will add phone contacts to the list of respondents.

Let's be objective - the Mail.Ru email application is made to last. And if earlier you used sophisticated pushes, enjoyed avatars in the list of letters, etc. was possible only if you had a mailbox on Mail.Ru, now users of the same Mail.Ru will be able to collect other mailboxes in the application (and those who prefer other services can at least test the client).

Last time, I started a series of articles about collecting mail from several different mailboxes, created even on different services, into one main mailbox, which the user constantly controls and it is easier for him to work with only one of them, rather than separately viewing all his email mailboxes. Read more about the need to collect mail and its implementation on the GMail service.

I am planning this series of articles for 3 articles so far. Today I’ll tell you about setting up mail collection in an equally well-known mail service - Yandex.

Collecting mail from other accounts in Yandex is set up just as easily as in other services.

The process of setting up mail collection in the Yandex service.

To enable the ability to collect all mail in your Yandex mailbox from any of your accounts on the same or other mail services, first log into your Yandex account, which will be the main one. This is where you will collect mail from other mailboxes.

Open the mail settings section and select “Collect mail from other mailboxes.”

You can collect mail from any mailboxes located on any mail services, and not just from your mailboxes located on the same Yandex service!

The example for this article will show the process of collecting letters from Mail.ru mail.

Enter the full email address from which you will collect letters and the password from it, then click “Enable collector”.

If you have specified the correct email login and password, a message indicating a successful connection will appear in the next window and here you can make some settings for collecting emails. For example, you can assign a label to collected emails, and also display old forwarded emails as read. Check the options you need, then below again enter the password for your second email and click “Save changes”. The mail will start collecting in about 10 minutes.

In this settings window, you will not be able to select a separate folder for collecting letters from a connected mailbox. Initially, the “Inbox” folder will be indicated and it does not change. This is due to the fact that initially mail is collected using the IMAP protocol and this protocol copies the entire folder structure from your connected mail.

If there are 2 options to force the collected mail to be sorted into folders:

    Change the mail collection settings and install the POP3 protocol instead of IMAP (which is set initially);

    Set up letter filtering later, i.e. create a condition under which received mail will end up in the folder you need, bypassing the “Inbox”.

The second option, I think, is more preferable, especially for beginners, so as not to fiddle with the settings for connecting to other mail.

Now all letters arriving at your connected mail will flow into the current one, which is your main one. And then there is no need to go into the second mail separately to check new letters in it.

How can I view separately all letters collected from connected mail?

After adding mail, you will see a label with its name on the left under the mail folders. Example:

By clicking on this shortcut you will see separately all the letters from the connected mailbox.

How can I change settings or disable mail collection from a specific mailbox?

If you need to change anything in the settings for collecting mail from an added mailbox, you can do this there in the Yandex mail settings, through the “Collecting mail from other mailboxes” section.

If you need to turn mail collection off or on again from a specific connected mailbox, click on the “On” switch. / Off.” in the list of connected mailboxes.

If you need to open mail collection settings, click on the name of the mailbox, and then click on the “Configure” link that appears. As a result, the same settings window will open as when connecting mail ().

Conclusion.

In conclusion, I would like to note that usually there are no problems with collecting email into the Yandex service and you don’t need to configure anything in the second email (which you connect). But there is a very capricious service called GMail :) When connecting to it (and not only to Yandex, but even to yourself), problems very often arise and this is due to the increased security of this Google mail. No, I don’t argue, safety is good! But sometimes this reaches the level of insanity, for example, when Gmail blocks the connection to its own second GMail mailbox, and both are logged in from the same computer and the same IP :)) I will talk about similar problems with connecting Google mail in a separate article.

Today these are perhaps the most popular email services. And when considering this or that resource, we casually agreed that each mailbox can be connected to a different email address from a different service.

After all, going to every mailbox and checking mail is not always convenient. Therefore, for convenience, the ability to add a mailbox to an existing address was created. Then all mail will be collected in one place, in one mailbox. Today we will learn how to organize the collection of mail from other mailboxes.

Let's start with Mail ru

How to add a mailbox to Mail ru

The mail ru mail service provides the ability to add a third-party mailbox to your main one.

In order to add another mailbox, go to your main mail ru mail account and click on your address at the top right

And click on the button “ to add a mail box».

After entering the data, click " To come in».

As a result of our actions, a folder appeared with our first and last name, and letters from Yandex mail will be delivered there. And you will no longer need to go to your Yandex mailbox to check new mail.

Now we’ll do something similar in Yandex mail.

How to add a mailbox to Yandex?

To add a mailbox from another mail service in the Yandex system, also log into your Yandex mail account

And click on the gear icon and select “ Collecting mail from other mailboxes».

Go to Settings " Mail collection" Now we will add a mailbox from mail ru. Enter our email address, its password and click “ Enable Collector»

At the next stage, you can specify a label for letters from Mail. All letters from the mail service will be sent to the Inbox folder. Let old emails be marked as read. Next, enter the password again and click “ Save changes».

That's it, we have connected an additional mailbox to Yandex mail. If in the future you no longer want to receive emails from your connected mailbox, you can disable it at any time.

You can add other boxes in a similar way.

To switch between the main and added boxes, use the main menu, then select the box you need.

How to add a mailbox to Gmail?

Mail from Google also allows you to connect an additional 5 mailboxes.

And select the item ""

Go to the tab " Accounts and import" and click on the link " Add an email account»

In the new window, enter the address of the mailbox that we will add. Click " Further».

Then, one by one, specify the password for the mailbox to be added, then change the POP server to pop3.mail. ru. Check the box that ensures that copies of received emails are saved on the server. This will be your safety net in case something happens to your Google account; your emails will be saved on the mail ru server. To make it easier to recognize which mailbox the letter came to, add a label to all incoming letters from mail ru

After that, click “ Add account».

On the next page we don’t change anything like that, except you can set your own Username. Enter the password for your mailbox and click “ Add account».

After this, an email with a confirmation code will be sent to your added mailbox. You can confirm in two ways: follow the link in the letter or copy the code from the letter and paste it into the field. Click " Confirm».

Now the settings have changed. As you can see in the screenshot below, our added email address has appeared, which can be changed or deleted.

You can also set the default mailbox from mail ru to send letters by clicking on the corresponding link.

And now the letters from the mail ru mailbox have successfully arrived in the mailbox from Google. As you can see, all letters are marked with a label that we specified during the process of adding a mailbox.

And when creating a new letter, you can choose which mailbox you want to send the letter from.

You can also use special programs - email clients - to collect letters in one place. The most popular is " The Bat" But this program is paid. Among the free ones - Mozilla Thunderbird. Read about that on our website.

Write in the comments whether you use email clients or a letter collector, as we described today.

Let me finish here. Good luck and success to all of you!

We should strive not to ensure that everyone understands us, but to ensure that it is impossible not to understand us.

Of course, everything must be parallelized. This is where my favorite library, TPL DataFlow, comes into play.

We will collect mail via POP3. All the “fashionable things” of IMAP are unnecessary in this task - you need to pick up the source code of the letter as quickly and easily as possible and delete it on the server. POP3 is enough here for the eyes. We use OpenPop.NET.

As an option, let's add monitoring to Zabbix. (We are going to work 24/7 and deliver the vaunted speed - we need to keep an eye on this).

Go

Let's create a regular console application. Open the NuGet console and install all the necessary packages:

Install-Package Nlog Install-Package OpenPop.NET Install-Package TopShelf Install-Package Microsoft.TPL.DataFlow
Go to the project folder, create App.Debug.config and App.Release.config. We unload the project from the studio, open its code (Hereinafter TopCrawler.csproj). Add to the config section:

Configurations

App.config App.config


And below is our own target for MSBuild:

Transform target

$(TargetFileName).config


Personally, I’m used to adding transformation of configs to separate environments in exactly this way - the old fashioned way.
For convenience, I offer strongly-type configs. A separate class will read the configuration. (You can discuss the theoretical aspects of such a solution in the comments). Configs, logs, monitoring are an excellent reason to implement the Singleton pattern.

We create a folder of the same name in the project (there must be order). Inside we create 3 classes - Config, Logger, Zabbix. Our logger:

Logger

static class Logger ( public static NLog.Logger Log ( get; private set; ) public static NLog.Logger Archive ( get; private set; ) static Logger() ( Log = LogManager.GetLogger("Global"); Archive = LogManager. GetLogger("Archivator");


Monitoring with Zabbix deserves a separate post, so I’ll just leave here the class that implements the agent:

Zabbix

namespace TopCrawler.Singleton ( ///

/// Singleton: zabbix sender class /// static class Zabbix ( public static ZabbixSender Sender ( get; private set; ) static Zabbix() ( Sender = new ZabbixSender(Config.ZabbixServer, Config.ZabbixPort); ) ) struct ZabbixItem ( public string Host; public string Key; public string Value ; ) class ZabbixSender ( internal struct SendItem ( // ReSharper disable InconsistentNaming - Zabbix is ​​case sensitive public string host; public string key; public string value; public string clock; // ReSharper restore InconsistentNaming ) #pragma warning disable 0649 internal struct ZabbixResponse ( public string Response; public string Info ) #pragma warning restore 0649 #region --- Constants --- public const string DefaultHeader = "ZBXD\x01"; public const string SendRequest = "sender data"; ; #endregion #region --- Fields --- private readonly DateTime _dtUnixMinTime = DateTime.SpecifyKind(new DateTime(1970, 1, 1), DateTimeKind.Utc); private readonly string _zabbixserver; private readonly int _zabbixport; (lstData.Count); values.AddRange(lstData.Select(itm => new SendItem ( host = itm.Host, key = itm.Key, value = itm.Value, clock = Math.Floor((DateTime.Now.ToUniversalTime() - _dtUnixMinTime). TotalSeconds).ToString(CultureInfo.InvariantCulture) )));< size); } #endregion } }


var json = serializer.Serialize(new ( request = SendRequest, data = values.ToArray() ));

var header = Encoding.ASCII.GetBytes(DefaultHeader);



So, the host and port where it connects, the user and password - everything is clear here. Next is the type of box. Let's say the service is used by marketing (as well as other departments). They have mailboxes where auto-responses to mailings are sent, as well as FBL spam reports. The mailbox itself already categorizes the letter, so for such situations we immediately set the mailbox type. The DataFlow settings will become clearer later when we start creating objects. Here we will have our own sections in the config. There are a lot of manuals on how to do this, so I’ll just show you the result:

Defining types

#region --- Types --- static class MailboxType ( public const string Bo = "bo"; public const string Crm = "crm"; public const string Fbl = "fbl"; public const string Bounce = "bounce"; ) class MailboxInfo ( public string Type ( get; set; ) public string Hostname ( get; set; ) public string User ( get; set; ) public string Password ( get; set; ) public int Port ( get; set; ) ) class DataBlockOptions ( public int Maxdop ( get; set; ) public int BoundedCapacity ( get; set; ) public DataBlockOptions() ( Maxdop = 1; BoundedCapacity = 1; ) ) #endregion


Creating sections

///

/// Custom config section /// public class CustomSettingsConfigSection: ConfigurationSection ( public CredentialsCollection CredentialItems ( get ( return base["CredentialsList"] as CredentialsCollection; ) ) public DataBlockOptionsCollection DataFlowOptionsItems ( get ( return base["DataFlowOptionsList"] as DataBlockOptionsCollection; ) ) )


///

/// Custom collection - credentials list /// public class CredentialsCollection: ConfigurationElementCollection, IEnumerable ( protected override ConfigurationElement CreateNewElement() ( return new CredentialsElement(); ) protected override object GetElementKey(ConfigurationElement element) ( return ((CredentialsElement)element).Username; ) public CredentialsElement this ( get ( return BaseGet(index) as CredentialsElement; ) ) public new IEnumerator < Count; i++) { yield return BaseGet(i) as CredentialsElement; } } } /// /// Custom credentials item /// public class CredentialsElement: ConfigurationElement ( public string Hostname ( get ( return base["hostname"] as string; ) ) public string Username ( get ( return base["username"] as string; ) ) public string Password ( get ( return base ["password"] as string; ) ) public string Type ( get ( return base["type"] as string; ) ) public string Port ( get ( return base["port"] as string; ) ) ) /// /// Custom collection - DataBlock options list /// public class DataBlockOptionsCollection: ConfigurationElementCollection, IEnumerable ( protected override ConfigurationElement CreateNewElement() ( return new DataBlockOptionsElement(); ) protected override object GetElementKey(ConfigurationElement element) ( return ((DataBlockOptionsElement)element).Name; ) public CredentialsElement this ( get ( return BaseGet(index) as CredentialsElement; ) ) public new IEnumerator GetEnumerator() ( for (var i = 0; i< Count; i++) { yield return BaseGet(i) as DataBlockOptionsElement; } } } /// /// Custom DataBlock options item /// public class DataBlockOptionsElement: ConfigurationElement ( public string Name ( get ( return base["name"] as string; ) ) public string Maxdop ( get ( return base["maxdop"] as string; ) ) public string BoundedCapacity ( get ( return base ["boundedcapacity"] as string; ) ) )


I will not write the full implementation of the config; it is assumed that during the development process the parameters we need will be added there.

Let's read our custom settings like this:

Reading

public List CredentialsList ( get; private set; ) public Dictionary DataFlowOptionsList ( get; private set; ) ... static Config() ( try ( var customConfig = (CustomSettingsConfigSection)ConfigurationManager.GetSection("CustomSettings"); //Get mailboxes foreach (var item in customConfig.CredentialItems) CredentialsList.Add( new MailboxInfo ( Hostname = item.Hostname, Port = Convert.ToInt32(item.Port), User = item.Username, Type = item.Type, Password = item.Password )); //Get DataFlow settings foreach (var item in customConfig.DataFlowOptionsItems) DataFlowOptionsList.Add(item.Name, new DataBlockOptions ( Maxdop = Convert.ToInt32(item.Maxdop), BoundedCapacity = Convert.ToInt32(item.BoundedCapacity) ) ) catch (Exception ex) ( Logger.Log. Fatal("Error at reading config: (0)", ex.Message); throw;


Somehow it’s getting very long, and we haven’t even gotten to the most interesting part.

Let's skip the TopShelf harness, performance counters, and communication with the database for now and get down to business! We create the Crawler class - the core. First, let's read the email:

private volatile bool _stopPipeline;
... public void Start() ( do ( var getMailsTasks = _config.CredentialsList.Select(credentials => Task.Run(() => GetMails(credentials))).ToList(); foreach (var task in getMailsTasks) task .Wait(); Thread.Sleep(2000); while (!_stopPipeline); //Stop pipeline - wait for completion of all endpoints //The DataFlow pipeline will stop here if (_stopPipeline) Logger.Log.Warn("Pipeline has been stopped by user"); )

This is where laziness took its toll and I decided not to bother - if there are about 20-30 boxes, you can run a task for each one and not worry about the number of threads. (I allow you to throw tomatoes.)

Let's move on to the reading itself:
Private void GetMails(MailboxInfo info) ( try ( using (var client = new Pop3Client()) (

Let's immediately calculate the timings for accessing the mailbox - it will be useful for diagnosing the network and server load.
//Get Zabbix metrics var stopwatch = new Stopwatch();

stopwatch.Start();< count; i++) { try { var mailInfo = new MessageInfo { IsSpam = false, Mail = client.GetMessage(i + 1), Type = MessageType.UNKNOWN, Subtype = null, Recipient = null, Mailbox = info }; Logger.Log.Debug("Download message from "{0}". Size: {1}b", info.User, mailInfo.Mail.RawMessage.Length);
//Get mail count client.Connect(info.Hostname, info.Port, false);

client.Authenticate(info.User, info.Password);
stopwatch.Stop();

Sending data to Zabbix. It's simple - we indicate the host name (as it is entered in Zabbix), the key (again, strictly as in Zabbix) and the string value.

//Send it to Zabbix Zabbix.Sender.SendData(new ZabbixItem ( Host = Config.HostKey, Key = info.Type + Config.TimingKey, Value = stopwatch.ElapsedMilliseconds.ToString() ));

Logger.Log.Debug("Send [(0)] timing to Zabbix: connected to "(1)" as "(2)", timing (3)ms", info.Type, info.Hostname, info.User, stopwatch.ElapsedMilliseconds);



var count = client.GetMessageCount();

//Save every mail to archive Logger.Log.Debug("Archive message");
Logger.Archive.Info(Functions.MessageToString(mailInfo.Mail));

) catch (Exception ex) ( Logger.Log.Error("Parse email error: (0)", ex.Message); Functions.ErrorsCounters.Increment(); //Archive mail anyway Logger.Log.Debug("Archive message "); Logger.Archive.Info(Encoding.Default.GetString(client.GetMessageAsBytes(i + 1))); ) if (_config.DeleteMail) client.DeleteMessage(i + 1); if (_stopPipeline) break; ();
) Logger.Log.Debug("Done with "(0)"", info.User);

) ) catch (Exception ex) ( Logger.Log.Error("General error - type: (0), message: (1)", ex, ex.Message); Functions.ErrorsCounters.Increment(); ) )

Here we used static error counters (by mailbox type), where ErrorsCounters is:


Public static Dictionary

ErrorsCounters = new Dictionary

And the counters themselves can be done like this:

Counter.cs class Counter ( private long _counter; public Counter() ( _counter = 0; ) public void Increment() ( Interlocked.Increment(ref _counter); ) public long Read() ( return _counter; ) public long Refresh() ( return Interlocked .Exchange(ref _counter, 0); ) public void Add(long value) ( ​​Interlocked.Add(ref _counter, value); ) public void Set(long value) ( ​​Interlocked.Exchange(ref _counter, value); ) ) Let's move on to creating the pipeline. Let's say we have boxes where auto-responses pour in. Such letters need to be parsed (what kind of auto-reply is, from whom, for which mailing list, etc.) and put the result in a storage (DB). Let's say there are boxes where FBL reports fall. We immediately put such letters into the database. We consider all other letters “useful” - they need to be checked for spam and sent to an external system, for example, CRM. As you already understand, this example mainly considers the use of the collector for marketing tasks - collecting statistics on mail delivery, information about spam. So, we have decided on the work flow. We declare the necessary blocks in the Crawler class: Class MessageInfo ( public bool IsSpam ( get; set; ) public Message Mail ( get; set; ) public string Subtype ( get; set; ) public string Recipient ( get; set; ) public MessageType Type ( get; set; ) public MailboxInfo Mailbox ( get; set; ) ) class Crawler ( //Pipeline private TransformBlock _addToFblDataBlock; private ActionBlock
_addToBounceDataBlock;

... We create an initialization method and create pipeline blocks (to initialize the blocks we use our wonderful sections from the configs): Public void Init() ( //*** Create pipeline *** //Create TransformBlock to get message type var blockOptions = _config.GetDataBlockOptions("_sortMailDataBlock"); _sortMailDataBlock = new TransformBlock (mail => SortMail(mail), new ExecutionDataflowBlockOptions ( MaxDegreeOfParallelism = blockOptions.Maxdop, BoundedCapacity = blockOptions.BoundedCapacity )); //Create TransformBlock to filter spam blockOptions = _config.GetDataBlockOptions("_spamFilterDataBlock"); _spamFilterDataBlock = new TransformBlock (mail => FilterSpam(mail), new ExecutionDataflowBlockOptions ( MaxDegreeOfParallelism = blockOptions.Maxdop, BoundedCapacity = blockOptions.BoundedCapacity )); //Create TransformBlock to sort bounces blockOptions = _config.GetDataBlockOptions("_checkBounceDataBlock");
We assemble the conveyor in accordance with our diagram:

//*** Build pipeline *** _sortMailDataBlock.LinkTo(_spamFilterDataBlock, info => info.Type == MessageType.GENERAL); _sortMailDataBlock.LinkTo(_addToFblDataBlock, info => info.Type == MessageType.FBL); _sortMailDataBlock.LinkTo(_checkBounceDataBlock, info => info.Type == MessageType.BOUNCE);
_sortMailDataBlock.LinkTo(DataflowBlock.NullTarget

(), info => info.Type == MessageType.UNKNOWN); /*STUB*/ _checkBounceDataBlock.LinkTo(_identifyDataBlock);.

_identifyDataBlock.LinkTo(_addToBounceDataBlock);
_spamFilterDataBlock.LinkTo(_addToCrmDataBlock, info => !info.IsSpam);

_spamFilterDataBlock.LinkTo(DataflowBlock.NullTarget

public void Start() ( do ( var getMailsTasks = _config.CredentialsList.Select(credentials => Task.Run(() => GetMails(credentials))).ToList(); foreach (var task in getMailsTasks) task.Wait( ); Thread.Sleep(2000); while (!_stopPipeline); //Stop pipeline - wait for completion of all endpoints _addToCrmDataBlock.Completion.Wait(); .Completion.Wait(); if (_stopPipeline) Logger.Log.Warn("Pipeline has been stopped by user");


Let's move on to the delegates.
Sorting... Well, let’s say everything is simple for us (we can always make it more complicated):

Private MessageInfo SortMail(MessageInfo mail) ( switch (mail.Mailbox.Type) ( case MailboxType.Crm: mail.Type = MessageType.GENERAL; break; case MailboxType.Bounce: mail.Type = MessageType.BOUNCE; break; case MailboxType. Fbl: mail.Type = MessageType.FBL; break; return mail;
Spam filter. This is for homework - use SpamAssassin.
Here's your delegate:

Private MessageInfo FilterSpam(MessageInfo mail) ( //TODO: Add SpamAssassin logic return mail; )
And classes for working with the SpamAssassin API (link to the project).
And we move on to parsing letters. We parse auto replies. This is where MEF comes into play.
We create a project (dll) with interfaces for our plugins (Let's call it Interfaces).
Adding an interface:

Public interface ICondition ( string Check(Message mimeMessage); ) public interface IConditionMetadata ( Type Type ( get; ) )
And... that's it. Our TopCrawler depends on this project and the plugin project will also use it.
Let's create a new project (also a dll), call it Conditions.
Let's add auto-response types:

#region --- Types --- static class BounceType ( public const string Full = "BounceTypeFull"; public const string Timeout = "BounceTypeTimeout"; public const string Refused = "BounceTypeRefused"; public const string NotFound = "BounceTypeNotFound"; public const string Inactive = "BounceTypeInactive"; public const string OutOfOffice = "BounceTypeOutOffice"; public const string HostNotFound = "BounceTypeHostNotFound"; public const string NotAuthorized"; public const string ManyConnections = "BounceTypeManyConnections";
And the classes that implement our interface:

Public class ConditionNotFound1: ICondition ( public string Check(Message mimeMessage) ( if (!mimeMessage.MessagePart.IsMultiPart) return null; const string pattern = "Diagnostic-Code:.+smtp.+550"; var regexp = new Regex(pattern , RegexOptions.IgnoreCase); return mimeMessage.MessagePart.MessageParts.Any(part => part.ContentType.MediaType == "message/delivery-status" && regexp.IsMatch(part.GetBodyAsText())) ? ; ) ) ... public class ConditionTimeout2: ICondition ( return BounceType.Timeout; ) ...
As you noticed, it's all about attributes. Using them, plugins will be loaded.
Let's return to our project and load the plugins:

Class Crawler ( ... //Plugins public IEnumerable > BounceTypeConditions ( get; set; ) private void LoadPlugins() ( try ( var container = new CompositionContainer(new DirectoryCatalog(_config.PluginDirectory), true); container.ComposeParts(this); ) catch (Exception ex) ( Logger.Log .Error("Unable to load plugins: (0)", ex.Message) ) ...
We pull LoadPlugins in the constructor of our class. I won’t explain in detail about the download mechanism - Google will do a better job.

Let's move on to our Bounce type check delegate. The conditions will be applied in turn until the first - exclusion method - works:

Private MessageInfo BounceTypeCheck(MessageInfo mailInfo) ( try ( foreach (var condition in BounceTypeConditions) ( var res = condition.Value.Check(mailInfo.Mail); if (res == null) continue; mailInfo.Subtype = res; Logger.Log .Debug("Bounce type condition [(0)] triggered for message [(1)]", condition.Metadata.Type, mailInfo.Mail.Headers.MessageId); break; catch (Exception ex) ( Logger.Log .Error("Failed to determine bounce type for message "(0)": (1)", mailInfo.Mail.Headers.MessageId, ex.Message); Logger.ErrorsCounters.Increment(); return mailInfo;
Thus, if a new logic module appears, you just need to add a new class to the project with plugins that implements our interface and - voila! I won’t attach an example of the second plugin for determining the sender of a letter - this is already a long post (The auto-reply was generated by the server itself, so the sender also needs to be parsed from the headers of the letter).

There is also nothing unusual about recording the results in the database. For example, like this:

Private void AddToBounce(MessageInfo mail) ( try ( MailWH.BounceAdd(mail); Functions.ProcessedCounters.Increment(); Functions.Log.Debug("Send Bounce to MailWH"); ) catch (Exception ex) ( Functions.Log. Error("Error saving Bounce message "(0)" to MailWH: (1)", mail.Mail.Headers.MessageId, ex.Message Functions.ErrorsCounters.Increment());

BounceAdd

public static long BounceAdd(MessageInfo message) ( using (var conn = new SqlConnection(ConnectionString)) using (var cmd = new SqlDataAdapter("BounceAdd", conn)) ( var body = message.Mail.FindFirstPlainTextVersion() == null ? message.Mail.FindFirstHtmlVersion().GetBodyAsText() : message.Mail.FindFirstPlainTextVersion().GetBodyAsText(); var outId = new SqlParameter("@ID", SqlDbType.BigInt) ( Direction = ParameterDirection.Output ); .CommandType = CommandType.StoredProcedure; cmd.SelectCommand.Parameters.Add(new SqlParameter("@RawMessage", message.Mail.RawMessage)); cmd.SelectCommand.Parameters.Add(new SqlParameter("@Message", body)) ; cmd.SelectCommand.Parameters.Add(new SqlParameter("@Subject", message.Mail.Headers.Subject ?? "")); cmd.SelectCommand.Parameters.Add(new SqlParameter("@MessageID", message.Mail .Headers.MessageId ?? "")); cmd.SelectCommand.Parameters.Add(new SqlParameter("@AddressTo", message.Mail.Headers.To.Address ?? "")); cmd.SelectCommand.Parameters.Add (new SqlParameter("@AddressFrom", message.Mail.Headers.From.Address ?? ""));


cmd.SelectCommand.Parameters.Add(new SqlParameter("@DateRecieved", DateTime.Now));

cmd.SelectCommand.Parameters.Add(new SqlParameter("@BounceTypeSysName", (object)message.Subtype ?? DBNull.Value));

In this tutorial, we learned that the task of collecting mail may not be so simple. The developed core allows you to quickly add new process steps - DataFlow blocks, without affecting the existing logic. The plugin subsystem allows you to quickly expand script-like parsing logic, and DataFlow itself parallelizes all calculations (and we have the ability to flexibly configure multithreading for a specific machine). TopShelf gives us the ability to run a service in both service mode and console mode for easier debugging.

Phew... If you're interested, I'll tell you how to put this on the rails of Continuous Integration, set up auto builds and release via VS Release Management.

Tags: Add tags