imap connection issue using ddeboer/imap - imap

I was trying to fetch mails from my gmail account using ddeboer/imap
$server = new Server('imap.gmail.com');
$connection = $server->authenticate('xxxxxxx#gmail.com', 'xxxxxx');
$mailbox = $connection->getMailbox('INBOX');
$messages = $mailbox->getMessages();
But $connection variable to showing error due to this I can't able to connect to my account.
Can anybody help?
Thanks in advance

Related

Microsoft Graph V1 API error: OData::ServerError 503 ConcurrentItemSave: "Conflicts occurred during saving data to store

I'm having trouble debugging the issue occurs when pushing new events to Outlook Calendar using Microsoft Graph API (v1). I have tested and it's still working, but I received this error which happened a few times today from my Ruby on Rails apps with the gems mentioned in the code snippet below. And there are duplicate events added to the calendar after these errors. I have searched this issue but still got nothing. Could anyone help me to debug this problem, please? I just don't know if this issue caused by my users' actions or just API server error. Many thanks!
OData::ServerError 503 ConcurrentItemSave: "Conflicts occurred during saving data to store (saveresult: IrresolvableConflict, properties: ). Please retry the request." from "https://graph.microsoft.com/v1.0/me/calendars/AAMkADg1YmMzNjE2LTM5Y2MtNGI2NC05NjJjLWRiY2RhZTZkNDRkMABGAAAAAADZc5aq6QclSqy_4oRMVv_EBwB4ZnW6S6xLTZDSXIsgJfprAAAAAAEGAAB4ZnW6S6xLTZDSXIsgJfprAAAGEcjmAAA=/events"
Code I use to create events via api
require 'adal'
require 'microsoft_graph'
username = ENV["OUTLOOK_USERNAME"]
password = ENV["OUTLOOK_PASSWORD"]
client_id = ENV["OUTLOOK_CLIENT_ID"]
client_secret = ENV["OUTLOOK_CLIENT_SECRET"]
tenant = ENV["OUTLOOK_TENANT"]
user_cred = ADAL::UserCredential.new(username, password)
client_cred = ADAL::ClientCredential.new(client_id, client_secret)
context = ADAL::AuthenticationContext.new(ADAL::Authority::WORLD_WIDE_AUTHORITY, tenant)
resource = "https://graph.microsoft.com/"
tokens = context.acquire_token_for_user(resource, client_cred, user_cred)
callback = Proc.new { |r|
r.headers["Authorization"] = "Bearer #{tokens.access_token}"
r.headers["Prefer"] = 'outlook.timezone="Australia/Sydney"'
r.headers['Content-type'] = 'application/json'
}
#graph = MicrosoftGraph.new(
base_url: "https://graph.microsoft.com/v1.0",
cached_metadata_file: File.join(MicrosoftGraph::CACHED_METADATA_DIRECTORY, "metadata_v1.0.xml"),
&callback
)
#example_data
calendar_id = "my_calendar_id"
data = my_event_object
#graph.service.post("me/calendars/#{calendar_id}/events", data.to_json)

OAuth2 authentication error using 'python-o365' library

I have able to successfully connect and read emails using the 'python-o365' library:
Connection.oauth2('Client_ID','Client_Secret',store_token=True)
inbox = FluentInbox()
for message in inbox.fetch_next(2):
print(message.getSubject())
However, when I try to send an email using a more basic example, I am receiving a 401 response from the server.
Connection.oauth2('Client_ID','Client_Secret',store_token=True)
att = Attachment(path=FilePath)
m = Message()
m.setRecipients(EmailTo)
m.setSubject('DBM Errors Identified - ' + FileName)
m.setBody(MessageBody)
m.attachments.append(att)
m.sendMessage()
I have also tried setting the connection object and passing it through as a parameter:
auth = Connection.oauth2('Client_ID','Client_Secret',store_token=True)
m = Message(*auth=auth*)
That however results in an error message of:
TypeError: 'Connection' object is not callable
Thanks for the help!
I was able to bypass the issue by switching to a fork of the 'python-o365' library that I used above. I feel like I am probably missing something obvious with that library but this solved the problem
Here is the simplified version of the authentication flow that I have working in case it interests anyone:
scopes = ['https://graph.microsoft.com/Mail.Read'']
account = Account(('Client_Id', 'Client_Secret'], auth_method='oauth',scopes=scopes)
account.connection.get_authroization_url() #generate the url for user to authenticate
result_url = input('Paste the result URL once you have authenticated...')
account.connection.get_session() #generate a session
m = account.new_message()
m.to.add('EmailTo')
m.body = 'MessageText'
m.send()

Not receiving response from Twilio.ListMessages after publishing to IIS

I am trying to use the following code to get the message status information from Twilio.
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var request = new MessageListRequest();
var messages = twilio.ListMessages(request);
foreach (var msg in messages.Messages){//Do something here}
I can receive the data when running in debug mode. But after publishing it to local computer in IIS, it stops working. I am getting null reference error. Can anyone give me direction or thought on how to resolve this issue? Thank you!
Deploy the source code into IIS (instead of the published fileset) and try debugging from there. Could be some permission issue to access any resource.

Don't send mails asp .net application hosted only work in localhost

I have a problem when I upload an application to the Web. I want to send a mail to several users but it doesn't work, but when I send in localhost work properly.
Here's my code to send the mail
System.Net.Mail.MailMessage correo = new System.Net.Mail.MailMessage();
correo.To.Add(mail_usuario);
correo.Body = cuerpomensaje;
correo.BodyEncoding = System.Text.Encoding.UTF8;
correo.Priority = System.Net.Mail.MailPriority.Normal;
correo.IsBodyHtml = true;//false tested too.
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
smtp.Host = "mail.cscdecision.com";
smtp.Credentials = new System.Net.NetworkCredential("id#domain.com", "IDPass");
//smtp.Credentials = new System.Net.NetworkCredential(sMailEnvioEmpresaServicio , sClaveEmpresaServicio);
smtp.EnableSsl = true;
smtp.SendAsync(correo, null);
//smtp.Send(correo);
The error is: "Unable to send to all recipients"
Why in the localhost works and in the host No?
Error: System.Net.Mail.SmtpFailedRecipientsException: Unable to send to all recipients.
System.Net.Mail.SmtpFailedRecipientException: The mailbox is unavailable.
The server response was: 5.7.1 <csc#cscdecision.com> Access to <ccruz#decision.com.ec> not allowed
have you specified what port the mail server is on?
i.e smtp.port = 25 (or a different port for SSL)
it's possible your host is blocking the port you are using.
Are you sending to same domain name .? If yes so you have to configure that this domain has a remote mail server not localy .
This is common in cpanel hosts .when the domain has a remote mail server

Monitoring a mailbox for new email message using EWS Managed API

I'm working on a task which I never worked in earlier.
Task: Monitor a specific mailbox inbox on exchange server 2007. Iterate through all email messages(Just email messages), do some processing and move to a specific folder under same mailbox.
Work I did
// Create the binding
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
//service.Credentials = new WebCredentials("mailbox", "password", "mailbox#something.com");
service.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["ExchangeUsername"].ToString(), ConfigurationManager.AppSettings["ExchangePassword"].ToString(), "something/domain");
// Set the url.
//service.AutodiscoverUrl("mailbox#something.com");
service.Url = new Uri(ServiceUrl);
ItemView view = new ItemView(10);
view.Traversal = ItemTraversal.Shallow;
view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
List<SearchFilter> searchFilterCollection = new List<SearchFilter>();
//searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "MessageType"));
searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Subject, "test to be deleted"));
SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray());
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox, view);
For some reason i always get results.items.count = 9, but there is only one EmailMessage in Mailbox#something.com. Am i doing any thing wrong in searching. If inbox had 5 emails, then i should get count as 5 and loop through the 5 emails. Is there a way to query just the email messages? Any help is appreciated. Thank you.
I answered my own questiona a while ago, but forgot to update here. So when i said count was not matching, it was monitoring mailbox of impersonating account. Coincidentally, the impersonating account has a mailbox.

Resources