ফিল্টার পরিচালনা

আপনি একটি অ্যাকাউন্টের জন্য উন্নত ফিল্টারিং নিয়ম কনফিগার করতে ফিল্টার ব্যবহার করতে পারেন। ফিল্টারগুলি স্বয়ংক্রিয়ভাবে লেবেল যুক্ত বা সরাতে পারে বা ইনকামিং বার্তার বৈশিষ্ট্য বা বিষয়বস্তুর উপর ভিত্তি করে যাচাইকৃত উপনামে ইমেল ফরওয়ার্ড করতে পারে।

ফিল্টার তৈরি , তালিকা , পেতে বা মুছে ফেলার বিষয়ে তথ্যের জন্য, ফিল্টার রেফারেন্স দেখুন।

মানদণ্ড মিলে যাওয়া

আপনি প্রেরক, বিষয়ের তারিখ, আকার এবং বার্তা বিষয়বস্তুর মতো বৈশিষ্ট্য দ্বারা বার্তাগুলি ফিল্টার করতে পারেন। Gmail এর উন্নত সার্চ সিনট্যাক্স ব্যবহার করে যেকোন প্রশ্ন ফিল্টারেও ব্যবহার করা যেতে পারে। উদাহরণস্বরূপ, সাধারণ ফিল্টার প্যাটার্ন অন্তর্ভুক্ত:

ছাঁকনি মেলে
criteria.from='sender@example.com' sender@example.com থেকে সমস্ত ইমেল
criteria.size=10485760
criteria.sizeComparison='larger'
10MB এর থেকে বড় সব ইমেল
criteria.hasAttachment=true একটি সংযুক্তি সহ সমস্ত ইমেল
criteria.subject='[People with Pets]' স্ট্রিং সহ সমস্ত ইমেল [People with Pets] বিষয়ের মধ্যে
criteria.query='"my important project"' my important project স্ট্রিং ধারণকারী সমস্ত ইমেল
criteria.negatedQuery='"secret knock"' স্ট্রিং secret knock ধারণ করে না যে সমস্ত ইমেল

একটি ফিল্টারে একাধিক মানদণ্ড উপস্থিত থাকলে, একটি বার্তা অবশ্যই ফিল্টার প্রয়োগের জন্য সমস্ত মানদণ্ড পূরণ করবে৷

কর্ম

আপনি ফিল্টারের মানদণ্ডের সাথে মেলে এমন বার্তাগুলিতে একটি ক্রিয়া প্রয়োগ করতে পারেন৷ বার্তাগুলি একটি যাচাইকৃত ইমেল ঠিকানায় ফরোয়ার্ড করা হতে পারে, বা লেবেলগুলি যুক্ত বা সরানো হতে পারে৷

আপনি ইমেলের স্বভাব পরিবর্তন করতে লেবেল যোগ করতে বা সরাতে পারেন। উদাহরণস্বরূপ, কিছু সাধারণ কর্ম অন্তর্ভুক্ত:

কর্ম প্রভাব
action.removeLabelIds=['INBOX'] ইমেল সংরক্ষণ করুন (ইনবক্স এড়িয়ে যান)
action.removeLabelIds=['UNREAD'] পঠিত হিসেবে চিহ্নিত করুন
action.removeLabelIds=['SPAM'] কখনই স্প্যাম হিসেবে চিহ্নিত করবেন না
action.removeLabelIds=['IMPORTANT'] কখনই গুরুত্বপূর্ণ হিসেবে চিহ্নিত করবেন না
action.addLabelIds=['IMPORTANT'] গুরুত্বপূর্ণ হিসেবে চিহ্নিত করুন
action.addLabelIds=['TRASH'] ইমেইল মুছে দিন
action.addLabelIds=['STARRED'] তারকাচিহ্নিত হিসাবে চিহ্নিত করুন
action.addLabelIds=['<user label id>'] একটি ব্যবহারকারী-সংজ্ঞায়িত লেবেল দিয়ে মেল ট্যাগ করুন. ফিল্টার প্রতি শুধুমাত্র একটি ব্যবহারকারী-সংজ্ঞায়িত লেবেল অনুমোদিত।

উদাহরণ

একটি মেইলিং তালিকা থেকে বার্তাগুলিকে কীভাবে লেবেল এবং সংরক্ষণাগার করতে হয় তা দেখানো আরও সম্পূর্ণ উদাহরণ নিচে দেওয়া হল৷

জাভা

gmail/snippets/src/main/java/CreateFilter.java
import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.gmail.Gmail;
import com.google.api.services.gmail.GmailScopes;
import com.google.api.services.gmail.model.Filter;
import com.google.api.services.gmail.model.FilterAction;
import com.google.api.services.gmail.model.FilterCriteria;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Arrays;

/* Class to demonstrate the use of Gmail Create Filter API */
public class CreateFilter {
  /**
   * Create a new filter.
   *
   * @param labelId - ID of the user label to add
   * @return the created filter id, {@code null} otherwise.
   * @throws IOException - if service account credentials file not found.
   */
  public static String createNewFilter(String labelId) throws IOException {
        /* Load pre-authorized user credentials from the environment.
           TODO(developer) - See https://developers.google.com/identity for
            guides on implementing OAuth2 for your application. */
    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
        .createScoped(GmailScopes.GMAIL_SETTINGS_BASIC,
            GmailScopes.GMAIL_LABELS);
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);

    // Create the gmail API client
    Gmail service = new Gmail.Builder(new NetHttpTransport(),
        GsonFactory.getDefaultInstance(),
        requestInitializer)
        .setApplicationName("Gmail samples")
        .build();

    try {
      // Filter the mail from sender and archive them(skip the inbox)
      Filter filter = new Filter()
          .setCriteria(new FilterCriteria()
              .setFrom("gduser2@workspacesamples.dev"))
          .setAction(new FilterAction()
              .setAddLabelIds(Arrays.asList(labelId))
              .setRemoveLabelIds(Arrays.asList("INBOX")));

      Filter result = service.users().settings().filters().create("me", filter).execute();
      // Prints the new created filter ID
      System.out.println("Created filter " + result.getId());
      return result.getId();
    } catch (GoogleJsonResponseException e) {
      // TODO(developer) - handle error appropriately
      GoogleJsonError error = e.getDetails();
      if (error.getCode() == 403) {
        System.err.println("Unable to create filter: " + e.getDetails());
      } else {
        throw e;
      }
    }
    return null;
  }
}

পাইথন

gmail/snippet/settings snippets/create_filter.py
import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError


def create_filter():
  """Create a filter.
  Returns: Draft object, including filter id.

  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """
  creds, _ = google.auth.default()

  try:
    # create gmail api client
    service = build("gmail", "v1", credentials=creds)

    label_name = "IMPORTANT"
    filter_content = {
        "criteria": {"from": "gsuder1@workspacesamples.dev"},
        "action": {
            "addLabelIds": [label_name],
            "removeLabelIds": ["INBOX"],
        },
    }

    # pylint: disable=E1101
    result = (
        service.users()
        .settings()
        .filters()
        .create(userId="me", body=filter_content)
        .execute()
    )
    print(f'Created filter with id: {result.get("id")}')

  except HttpError as error:
    print(f"An error occurred: {error}")
    result = None

  return result.get("id")


if __name__ == "__main__":
  create_filter()