openpop.NET File, MessageHeader, RfcMailAddress, Message could not be found - c#

I am using openpop.net to read emails and print them after checking the subject.
However im stuck on the first step, MessageHeader, RfcMailAddress and File shows up as error "The type or namespace name "Message Header" could not be found".
I think i havnt declared the right references but not sure. I have declared the following references:
using OpenPop;
using OpenPop.Pop3;
using OpenPop.Mime;
using OpenPop.Common;
any help is appreciated.
my code is copied from http://hpop.sourceforge.net/exampleExamineHeaders.php
Below is how my code looks like

using OpenPop.Mime.Header;
MessageHeader headers = client.GetMessageHeaders(messageNumber);
RfcMailAddress from = headers.From;
string Subject = headers.Subject;

Use:
OpenPop.Mime.Header.MessageHeader headers = client.GetMessageHeaders(messageNumber);
OpenPop.Mime.Header.RfcMailAddress from = headers.From;

Related

422 unprocessable entity error received from pastebin POST request

I've been making a big project recently and have been trying to figure out how to make my C# .Net program post a string to Pastebin and return the URL of the paste created. I've gotten a few lines of code down (not mine, I found it on this site) but even after much troubleshooting I always get some kind of error from it. I'm not familiar with webrequest or any of the similar methods designed to interact with the internet, so I had to rely on advice from other people online, yet even after multiple hours worth of searching online for solutions to my problem I still get a (422) unprocessable entity error from my code when run:
using System.Net;
using System.IO;
using System.Text;
using System.IO;
public class Program
{
public static void Main()
{
WebRequest wr = WebRequest.Create("https://pastebin.com/api/api_post.php");
//ASCIIEncoding encoding = new ASCIIEncoding();
byte[] bData = Encoding.UTF8.GetBytes(string.Concat("api_option=paste&api_paste_code=", Console.ReadLine(), "&paste_private=0&api_dev_key=" + api_dev_key));
wr.Method = "POST";
wr.ContentType = "application/x-www-form-urlencoded";
wr.ContentLength = bData.Length;
Stream sMyStream = wr.GetRequestStream();
sMyStream.Write(bData, 0, bData.Length);
wr.GetResponse();
sMyStream.Close();
}
}
Exact error:
Run-time exception (line 36): The remote server returned an error: (422) Unprocessable Entity.
Stack Trace:
[System.Net.WebException: The remote server returned an error: (422) Unprocessable Entity.]
at System.Net.HttpWebRequest.GetResponse()
at Program.Main() :line 36
I've decided the best course of action to take to solve my problem is just to get help directly from people who know this kind of stuff well. I've just been running this code on dotnetfiddle. If you need more information please ask.
Edits: updated a few parameters (such as api_option)
After taking a look at the docs I think you're using a unsuitable parameter (paste_subdomain) for posting your API key.
Have a try using api_dev_key instead:
byte[] bData = Encoding.UTF8.GetBytes(string.Concat("paste_code=", encoded, "&paste_private=0&paste_expire_date=1D&api_dev_key=" + api_dev_key));
If this doesn't work, better have a look at the other parameters, too.
Just a blind guess, but probably the error occurs because you don't url-encode the code to be posted.
Maybe it'll do the trick if you encode the code entered:
var toBePosted = Console.ReadLine();
var encoded = HttpUtility.UrlEncode(toBePosted);
byte[] bData = Encoding.UTF8.GetBytes(string.Concat("paste_code=", encoded, "&paste_private=0&paste_expire_date=1D&paste_subdomain=" + api_dev_key));
I've had working code for a while, and just recently got this error showing up on one of my bots that paste to pastebin.. worked fine # 1230MST started erroring # 100pm MST..
Could be something on their end, and nothing has changed here, and its worked for many years.

Delete message using AE.Net.Mail

I'm trying to delete some specific emails. I'm using AE.Net.Mail. I tried a few thinks but nothing worked yet. I've read about expunge, somethink that could work. So far it hasn't and i have the feeling it doesn't work with AE.Net.Mail.
So can you guys help me out?
I filter the messages like this:
var Mail = imap.SearchMessages(SearchCondition.Subject("Generated Report"));!
Have you tried the following?
List<Lazy<MailMessage>> Mail = imap.SearchMessages(
SearchCondition.Subject("Generated Report")).ToList();
imap.DeleteMessage(Mail.First().Value);
imap.Expunge();

Unsupported Media Type error when using json-patch in Ramone

Update: I downloaded Ramone project, added it to my project and then ran the application again with debugger. The error is shown below:
public MediaTypeWriterRegistration GetWriter(Type t, MediaType mediaType)
{
...
CodecEntry entry = SelectWriters(t, mediaType).FirstOrDefault(); => this line throws error
...
}
Error occurs in CodecManager.cs. I am trying to figure out why it does not recognize json-patch media type. Could it be because writer is not being registered correctly? I am looking into it. If you figure out the problem, please let me know. Since you are the author of the library, it will be easier for you to figure out the issue. I will have to go through all the code files and methods to find the issue. Thanks!
I was excited to know that Ramone library supports json-patch operations but when I tried it, I got following error:
415- Unsupported Media Type
This is the same error that I get when I use RestSharp. I thought may be RestSharp does not support json-patch and errors out so I decided to try Ramone lib but I still get same error. Endpoint has no issues because when I try same command using Postman, it works but when I try it programmatically in C#, it throws unsupported media type error. Here is my code:
var authenticator = new TokenProvider("gfdsfdsfdsafdsafsadfsdrj5o97jgvegh", "sadfdsafdsafdsfgfdhgfhehrerhgJ");
JsonPatchDocument patch = new JsonPatchDocument<MetaData>();
patch.Add("/Resident2", "Boyle");
//patch.Replace("/Resident", "Boyle");
RSession = RamoneConfiguration.NewSession(new Uri("https://api.box.com"));
RSession.DefaultRequestMediaType = MediaType.ApplicationJson;
RSession.DefaultResponseMediaType = MediaType.ApplicationJson;
Ramone.Request ramonerequest = RSession.Bind("/2.0/files/323433290812/metadata");
ramonerequest.Header("Authorization", "Bearer " + authenticator.GetAccessToken(code).AccessToken);
//var ramoneresponse = ramonerequest.Patch(patch); //results in error: 405 - Method Not Allowed
var ramoneresponse = ramonerequest.Put(patch); //results in error: 415 - Unsupported Media Type
var responsebody = ramoneresponse.Body
Endpoint information is available here: http://developers.box.com/metadata-api
I used json-patch section in the following article as a reference:
http://elfisk.dk/Ramone/Documentation/Ramone.pdf
By the way I tried Patch() method (as shown in above ref. article) but that resulted in "Method not allowed" so I used Put() method which seems to work but then errors out because of json-patch operation.
Any help, guidance, tips in resolving this problem will be highly appreciated. Thanks much in advance.
-Sham
The Box documentation says you should use PUT (which is quite a bit funny). The server even tells you that it doesn't support the HTTP PATCH method (405 Method Not Allowed) - so PUT it must be.
Now, you tell Ramone to use JSON all the time (RSession.DefaultRequestMediaType = MediaType.ApplicationJson), so you end up PUT'ing a JSON document to Box - where you should be PUT'ing a JSON-Patch document.
Drop the "RSession.DefaultRequestMediaType = MediaType.ApplicationJson" statement and send the patch document as JSON-Patch with the use of: ramonerequest.ContentType("application/json-patch+json").Put(...).

FlourineFX rtmp ssl

I'm trying to connect to an rtmps server using C# and FluorineFX.
I'm doing this using this code
netConnection = new NetConnection();
netConnection.OnConnect += onConnect;
netConnection.NetStatus += netStatus;
netConnection.ObjectEncoding = ObjectEncoding.AMF3;
Console.WriteLine(netConnection.PlayerVersion = "WIN 10,1,85,3");
netConnection.Connect("rtmps://example.com:2099/");
example.com is replacing the real url in this example.
But this code only gives me an exception stating that:
System.UriFormatException: One of the identified items was in an invalid format
the FluorineFX webpage states that it supports rtmps, so i would think that would be the case. Any help would be greatly appreciated.
I found a github repo that adds RTMPS support into FlourineFX
https://github.com/epicvrvs/FluorineFXMods
All you need to do is follow the instructions in the top and compile it.

ExchangeServiceBinding namespace error

Summary: application will not accept the ExchangeServiceBinding command.
Details:
I am trying to loop through a very large mailbox, so I am using an index to break the inbox into 200 email chunks. The only example I could find (shown below) keeps returning
the type or namespace name “ExchangeServiceBinding” could not be found (are you missing a using directive or an assembly reference? )
Which I find strange, because I am using it using Microsoft.Exchange.WebServices;. Any ideas or help is greatly appreciated. I am running Windows 7 and Visual Studio 2010 and trying to access Exchange 2007 mailboxes.
Things I've tried:
searching Google
searching Stack Overflow
searching MSDN
slamming my head on my desk
trial and error
Code:
// Create binding variable to be used for GetItemsFromInbox().
// Set up the binding with credentials and URL.
ExchangeServiceBinding binding = new ExchangeServiceBinding();
binding.Credentials = new NetworkCredential(dUser, dPassword, dDomain);
binding.Url = new Uri("https://" + ExchangeServerName + "/EWS/Exchange.asmx");
// Set up the binding for Exchange impersonation.
binding.ExchangeImpersonation = new ExchangeImpersonationType();
binding.ExchangeImpersonation.ConnectingSID = new ConnectingSIDType();
binding.ExchangeImpersonation.ConnectingSID.PrimarySmtpAddress = "mailboxnamehere”;
// Call GetItemsFromInbox()
int index = 0;
bool looping = true;
while (looping)
{
List<ItemType> items = GetItemsFromInbox(binding, index, 200, index);
if (items == null || items.count == 0)
{
looping = false;
break;
}
// Do your work here
}
Instead of the Exchange Web Services, use the Exchange Managed API.
SDK: http://msdn.microsoft.com/en-us/library/dd633710(v=exchg.80).aspx
Download: http://www.microsoft.com/download/en/details.aspx?id=13480
It's much easier to use than the WebServices.
I found my error. This methodology only works for Exchange 2010. Since I am running Exchange 2007 I will have to figure out a completely different way to make this work.
Thank you everyone for you help, I really appreciate it.
You should add a WebReference to your solution to the exchange WebService.
https://exchaneServerName/EWS/Exchange.asmx
ExchangeServiceBinding is contained into the ews.dll. According to your error, you didn't add a reference to this DLL file.
More information about Generating Exchange Web Services Proxy Classes:
So now you have a code file with the autogenerated proxies. Next, you compile your code file into an assembly for use in your Exchange Web Services projects. The C# compiler is available with the Visual Studio 2005 Command Prompt. Assuming that you named your code file EWS.cs, you can run the following command at the command prompt to compile your code into an assembly:
csc /target:library /out:EWS.dll EWS.cs
Notice that EWS.dll is the name of the compiled assembly. This is how EWS.dll is created.

Categories

Resources