|
You should at least catch an SmptException , which will be thrown if for any reason the email was unable to be sent. You can use the SmtpStatusCode enum to find out the reason, something like this:_
try
{
client.Send(message);
}
catch (SmtpException ex)
{
MessageBox.Show(String.Format("Error: {0}", ex.StatusCode));
}
Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Here is what I do.
string RetMsg = string.Empty;
try
{
client.Send(message);
RetMsg = "Success";
}
catch (SmtpException ex)
{
RetMsg = String.Format("Error: {0}", ex.StatusCode);
}
MessageBox.Show(RetMsg);
Now I receiver's email address something like: "address@yaho.com". You see there is problem with the mail address? But it still shows me Success. What's wrong?
|
|
|
|
|
There is nothing wrong with that email address; there may well be a domain out there called yaho.com. However, if that domain does not exist the SMTP system will send you a message telling you that the email is undeliverable; but that will not cause an exception in your code.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
SmtpClient has no conception of correct email addresses. It will send the message to any address you type in, regardless of whether it is a correct address or not. You will only get notification that the sending failed from your smtp server. If you want to send messages to correct email addresses, you will need to construct your own validation routine, using something like regular expressions or a list of known(authorised) addresses, and pass all messages through that first before sending.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
that's not good enough. You should use sendasync coupled with a completeCallback.
Then you should have the error/delivery failure. That depends on the SMTP Mail server itself that you are using. See here
All the best,
Dan
|
|
|
|
|
I have 3 classes:
[Serializable]
public class _ModelBase
{
public Guid Id { get; set; }
public string Caption { get; set; }
public string Description { get; set; }
public bool IsActive { get; set; }
public int Sequence { get; set; }
public ImageSource Image { get; set; }
}
and
[Serializable]
public class FolderModel : _ModelBase
{
public List<FolderModel> Folders { get; set; }
public List<FileModel> Files { get; set; }
public bool IsExpanded { get; set; }
public FolderModel()
{
Folders = new List<FolderModel>();
Files = new List<FileModel>();
}
}
and
[Serializable]
public class FileModel : _ModelBase
{
public string FileName { get; set; }
}
I'm trying to serialize a a collection of FolderModels and FileModels:
private void saveAppDataToFile()
{
using (TextWriter textWriter = new StreamWriter(xmlDataFile))
{
XmlSerializer serializer = new XmlSerializer(typeof(FolderModel));
serializer.Serialize(textWriter, Folders);
textWriter.Close();
}
}
I'm gettng the runtime error
"There was an error generating the XML document."
"Unable to cast object of type 'System.Collections.Generic.List`1[MyApp.Models.FolderModel]' to type 'MyApp.Models.FolderModel'"}
I can't figure out why this won't work. Anyone see what's wrong?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
Kevin Marois wrote: a collection of FolderModels and FileModels I think it would be useful to see the structure/definition of that Collection.
"Anyone who shows me my 'blind spots' gives me the gift of sight." ... a thought from the shallows of the deeply shallow mind of ... Bill
|
|
|
|
|
I think there is an issue around the xml serialising of complex object, your List<>s make this a complex object. There are literally dozens of alternative serialisers and many articles written on the subject.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yeah just like Microft Mycroft Holmes said. It doesn't let you serialize a collection.
Instead use a foreach and serialize each folder indivitually.
Something like:
using (TextWriter textWriter = new StreamWriter(xmlDataFile))
{
XmlSerializer serializer = new XmlSerializer(typeof(FolderModel));
foreach(folder in Folders) serializer.Serialize(textWriter, folder);
textWriter.Close();
}
All the best,
Dan
|
|
|
|
|
This is a fairly simple one to fix and the error is actually pretty helpful. You told the serializer that you were going to serialize FolderModel but you then try to serialize a list of FolderModel instead.
|
|
|
|
|
SLAP!
That's the sound of me slapping myself.
Thanks!
Everything makes sense in someone's mind
|
|
|
|
|
Hey, no problem. If I hadn't made a similar mistake several thousand times, I'd probably have missed it.
|
|
|
|
|
I find this code a challenge to understand because it appears to me there's a circular (recursive) reference inherent in the structure of the FolderModel class.
Assuming there's no recursion inherent in the data structure itself: all he has to do is to call:
serializer.Serialize(textWriter, FolderModel1); And that's it ?
Your brilliance is shining through again
thanks, Bill
"Anyone who shows me my 'blind spots' gives me the gift of sight." ... a thought from the shallows of the deeply shallow mind of ... Bill
|
|
|
|
|
Hi all,
I got some user filled PDF forms, from there i need to extract the user filled data.Is there any possible way using C# other than 3rd party tool?
Thanks in advance
|
|
|
|
|
No, there is no native support for PDF files built-in to .NET. You'll need to use one of the many 3rd party libraries.
No comment
|
|
|
|
|
|
Thanks for your reply, but i need to fetch the user filled fields.
Is there any way to fetch those field values/tables?
|
|
|
|
|
Hi,
I am hosting an ActivX control in C#. The control has a method as follows...
GetMinMaxVals(bouble* pdMinX, double* pdMaxX, double* pdMinY, double* pdMaxY);
The caller may pass null (zero) for any of the parameters that are not required. I only need a value for pdMaxX.
Question is: How do I pass null for the arguments i do not require?
Thanks - John.
|
|
|
|
|
I don't see a problem. What does your code look like? What have you tried? How does it fail?
|
|
|
|
|
You may need to declare the parameters as IntPtr not ref double. As far as I'm aware it's not possible to pass a null pointer (as opposed to a pointer to null) through a ref or out parameter – it's rather the point of them to stop you accidentally referencing null pointers, after all.
|
|
|
|
|
Thanks for the replies,
@Bob, how would I change the argument type to IntPtr (sounds like it could be a solution), when the method is exposed from the interop dll's generated by VisualStudio?
Thanks - John.
|
|
|
|
|
You have to manually edit the interop C# it produces, I think. I realise this is non-ideal but tlbimp isn't that clever and it makes assumptions (like pointer -> ref) that aren't necessarily valid, so it's sometimes necessary.
|
|
|
|
|
Just change the DllImport decorated function to use IntPtr instead of double :
[DllImport("thedll.dll", SetLastError = true)]
public static extern void GetMinMaxVals(IntPtr pdMinX, ref double pdMaxX, IntPtr pdMinY, IntPtr pdMaxY);
You can then call this like:
double pdMaxX = 0;
GetMinMaxVals(IntPtr.Zero, ref pdMaxX, IntPtr.Zero, IntPtr.Zero);
Change the value of pdMaxX to whatever is suitable for the call. If it only passes a value out and doesn't require one in, then use out instead of ref .
[DllImport("thedll.dll", SetLastError = true)]
public static extern void GetMinMaxVals(IntPtr pdMinX, out double pdMaxX, IntPtr pdMinY, IntPtr pdMaxY);
double pdMaxX;
GetMinMaxVals(IntPtr.Zero, out pdMaxX, IntPtr.Zero, IntPtr.Zero);
If the function returns a value then amend as required.
|
|
|
|
|
So how does the called routine decide which parameters are required and which are not? You could just as easily pass a ref to some special value (0.0, -1.0 etc).
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I'm not confident on this as I obviously don't have the OPs code or API for the ActiveX, but I would guess from the info provided that it looks for null pointers, the .NET equivalent of System.IntPtr.Zero .
I've never looked into this, but doesn't a ref parameter marshal the address at which the actual value is stored, therefore passing 0.0 could pass a pointer to any valid memory address rather than a null (zero) pointer? This could be way wrong - I will research!
|
|
|
|