What programing languages can be used to send emails [closed] - windows

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am about to start writing a program that will have a GUI interface with the user that prompts for a number between 1-100. The program then emails me that number(this program would be running on an unknown users computer).
I am unable to decide what programing language to use for such a project. Can anyone suggest a language that is able to do GUI, and send emails from someone elses computer? (Preferable be able to save this program as a .exe or some single file that can be run from their computer. Also would prefer a link as to how to email in that language, but I am fine doing that research myself, just unsure what language to start researching in. If I left anything out please leave a comment asking for clarification. Thanks for any help I can get.

Use C# cus you know it's awesome (heavily biased answer) and here's the code
private bool sendMsg (string from, string to, string subject , string messageBody)
{
MailMessage message = null;
try
{
message = new MailMessage(from, to);
using (message) {
message.Subject = subject;
//message.CC.Add(CCemailAddress);
message.Body = messageBody;
message.IsBodyHtml = false;
SmtpClient client = new SmtpClient("smtp.outlook.com", 587);
client.Credentials = new System.Net.NetworkCredential(from, "Sending Accounts Password");
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true; //enable SSL
client.Send(message);
client.Dispose();
}
}
catch
{
return false;
}
message.Dispose();
return true;
}

Related

Xamarin Extract Images from pdf file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a pdf file in my server and i want a method to download the pdf file and extract images from that file. So far i have used XamiTextSharpLGPLv2, pdfbox but no luck so far.
PdfReader reader = new PdfReader(new Uri(url));
for (int i = 1; i <= reader.NumberOfPages; i++)
{
PdfDictionary pg = reader.GetPageN(i);
iTextSharp.text.pdf.PdfObject PDFObj = reader.GetPdfObject(i);
if ((PDFObj != null) && PDFObj.IsStream())
{
iTextSharp.text.pdf.PdfStream PDFStremObj = (iTextSharp.text.pdf.PdfStream)PDFObj;
try
{
//var pdfImage = new PdfImageObject((PRStream)PDFStremObj);
//var img = pdfImage.GetDrawingImage();
}
catch (Exception)
{
}
}
}
PdfImageObject is not found in XamiTextSharpLGPLv2,
how can i use XamiTextSharpLGPLv2 to extract images or suggestions for any other library to achieve this would be a great help.
Thanks in advance.
Xamarin Extract Images from pdf file
here are two libraries to extract images from pdf file
XFINIUM.PDF
PDFTron

Documenting custom error codes from ASP.NET Web API [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Are there any best practices for documenting possible error codes returned from a Web API call? I'm referring to custom logic errors as opposed to standard HTTP return codes.
For example, consider an API method to allow a user to change their password. A possible error condition might be that the new password provided has already been used by that user previously (ie, password history requirement). You could use the following code to communicate that to the caller:
public HttpResponseMessage ChangePassword(string oldPassword, string newPassword)
{
try
{
passwordService.ChangePassword(oldPassword, newPassword)
return Request.CreateResponse(HttpStatusCode.OK);
}
catch (Exception ex)
{
switch(ex.Message)
{
case "PasswordHistoryFailed":
return Request.CreateResponse(HttpStatusCode.BadRequest, new CustomErrorClass("FailedHistoryRequirements"));
break;
...
}
}
}
In this example, I'm using a custom error class to wrap a custom error code of "FailedHistoryRequirements". I could have more error codes for this operation such as too many password changes in a 24 hour period or whatever.
I want to know if there's an accepted way to automatically document these custom error codes in the method's XML Code Comments so that it can be consumed by a documentation generator like Swashbuckle/Swagger or something similar.
If you use Swagger, you can use the SwaggerResponse attribute.
Check out this blog post:
https://mattfrear.com/2015/04/21/generating-swagger-example-responses-with-swashbuckle/
I do this by catching a specific exception type, rather than parsing the message.
Here I have MyDepartmentCentricBaseException as a custom exception. I may have 2-3 exceptions that derive from it. But by using a base-exception, I keep my exception catching cleaner.
try
{
/* do something */
}
catch (MyDepartmentCentricBaseException deptEx)
{
HttpResponseException hrex = this.GetDepartmentMissingHttpResponseException(deptEx.DepartmentSurrogateKey);
throw hrex;
}
catch (Exception ex)
{
/* log it somewhere !*/
throw new HttpResponseException(HttpStatusCode.InternalServerError);
}
private HttpResponseException GetDepartmentMissingHttpResponseException(int DepartmentSurrogateKey)
{
HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.NotFound)
{
Content = new StringContent(string.Format("No Department with DepartmentSurrogateKey = {0}", DepartmentSurrogateKey)),
ReasonPhrase = "DepartmentSurrogateKey Not Found"
};
HttpResponseException returnEx = new HttpResponseException(resp);
return returnEx;
}
There are other ideas here:
https://learn.microsoft.com/en-us/aspnet/web-api/overview/error-handling/exception-handling
But I don't know of a way of auto-voodoo-it with documentation. :(

Websphere MQ using XMS.Net [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I wanted to understand how can I use Web sphere MQ for the following scenario:
1.How I can read the message from the queue without removing that message from the queue.
2. We have a web application so we need the Listener to read the Queue. Is there any tool to do this ?
Yes, it's possible to read message without removing from a queue, it's known as Browsing. You will need to create a browser consumer to read the messages. I have posted snippet here, same code is available in Tools\dotnet\samples\cs\xms\simple\wmq\SimpleQueueBrowser\SimpleQueueBrowser.cs also.
// Create connection.
IConnection connectionWMQ = cf.CreateConnection();
// Create session
ISession sessionWMQ = connectionWMQ.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
// Create destination
IDestination destination = sessionWMQ.CreateQueue(queueName);
// Create consumer
IQueueBrowser queueBrowser = sessionWMQ.CreateBrowser(destination);
// Create message listener and assign it to consumer
MessageListener messageListener = new MessageListener(OnMessageCallback);
queueBrowser.MessageListener = messageListener;
// Start the connection to receive messages.
connectionWMQ.Start();
Callback method
static void OnMessageCallback(IMessage message)
{
try
{
// Display received message
Console.Write(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in OnMessageCallback: {0}", ex);
}
}

What api can I use to find the manufacturer of a system in Windows 8? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Windows VC++ Get Machine Model Name
I saw box.net detecting PC manufacturers and giving the users extra space in Windows 8. Which api can I use to find out the manufacturer?
You could use Windows Management Instrumentation
This example is in C#, hope it works for you.
string manufacturer = string.Empty;
ManagementClass mc = new System.Management.ManagementClass("Win32_BIOS");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (string.IsNullOrEmpty(result))
{
try
{
if (mo["Manufacturer"] != null)
manufacturer = mo["Manufacturer"].ToString();
break;
}
// Show the exception (just for test purpose)
catch(Exception ex)
{
MessageBox.Show(ex.Message)
}
}
}
Console.WriteLine(manufacturer.Trim());

asp.net mvc3, api twitter [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Somebody can explain me this code :
auth = new MvcAuthorizer
{
Credentials = credentials
};
auth.CompleteAuthorization(Request.Url);
var auth = new MvcAuthorizer
{
Credentials = new SessionStateCredentials()
{
ConsumerKey = this.client.ConsumerKey,
ConsumerSecret = this.client.ConsumerSecret,
OAuthToken = identity.Token.Token
}
};
the difference between the two codes
Thanks,
Logically, there is no difference. I'm making the assumption that "credentials" in the first example is a SessionStateCredentials that was instantiated previously in the code. The second example uses object initialization syntax to do the same thing.

Resources