Showing posts with label generic. Show all posts
Showing posts with label generic. Show all posts

Saturday, March 31, 2012

Sendmail config

I've been given the following template code:

// Generic method for sending emails

publicstaticvoid SendMail(string from,string to,string subject,string body)

{

// Configure mail client (may need additional// code for authenticated SMTP servers)SmtpClient mailClient =newSmtpClient

(

GuitarShackConfiguration.MailServer);// Create the mail message//MailMessage mailMessage = new MailMessage(from, to, subject, body);/*

// For SMTP servers that require authentication

message.Fields.Add

("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);

message.Fields.Add

("http://schemas.microsoft.com/cdo/configuration/sendusername",

"SmtpHostUserName");

message.Fields.Add

("http://schemas.microsoft.com/cdo/configuration/sendpassword",

"SmtpHostPassword");

*/

// Send mail//mailClient.Send(mailMessage);

}

but i can't seem to get it to work with any mailhosts. Could someone kindly show me how to make this work with someone like hotmail or gmail or even a regular pop3 mail provider?

First of all be aware that most of the mail server requires you to authenticate before sending emails. I'v attached a code where you can use to send emails below.


Dim MailObjAs New System.Net.Mail.SmtpClient MailObj.Host ="smtp server goes here"Dim credAs New Net.NetworkCredential("username","password")' authentication MailObj.Credentials = cred MailObj.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.NetworkDim msgAs New System.Net.Mail.MailMessageWith msg .Body ="Body goes here" .From =New System.Net.Mail.MailAddress("from email","from name") .To.Add("destination email address") .Subject ="subject goes here"End With MailObj.Send(msg)


Regards


First of all be aware that most of the mail server requires you to authenticate before sending emails. I'v attached a code where you can use to send emails below.


Dim MailObjAs New System.Net.Mail.SmtpClient
MailObj.Host ="smtp server goes here"
Dim credAs New Net.NetworkCredential("username","password")' authentication
MailObj.Credentials = cred
MailObj.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
Dim msgAs New System.Net.Mail.MailMessage
With msg
.Body ="Body goes here"
.From =New System.Net.Mail.MailAddress("from email","from name")
.To.Add("destination email address")
.Subject ="subject goes here"
End With

MailObj.Send(msg)


Regards


Hi,

Any question about Sending Mail may be answered at this website:

http://www.systemnetmail.com/

Good luck!

Monday, March 26, 2012

serialization - include collection property

Why the collection property is not included in the ouput
serialization ?

I have a custom generic collection (implements icollection): Events of
objects: Event.

Event is a simple class exposing, let's say, one property: name

Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class

Events Implements ICollection
Public EventColor as string
......

Everything works except when I save the xml file I'm expecting to get
smth like:

<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>

EVENTCOLOR attribute is not in the xml, any idea ?

Thanks,
xkeIn your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?

--
Andrew Faust
andrew[at]andrewfaust.com
http://www.andrewfaust.com
"xke" <xkeops@.gmail.comwrote in message
news:1193083502.735588.136230@.e34g2000pro.googlegr oups.com...

Quote:

Originally Posted by

Why the collection property is not included in the ouput
serialization ?
>
I have a custom generic collection (implements icollection): Events of
objects: Event.
>
Event is a simple class exposing, let's say, one property: name
>
Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class
>
>
Events Implements ICollection
Public EventColor as string
......
>
Everything works except when I save the xml file I'm expecting to get
smth like:
>
<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>
>
EVENTCOLOR attribute is not in the xml, any idea ?
>
Thanks,
xke
>


Hi Andrew,

Yes, EventName gets serialized as member of Event class. Question
would be: why the parent collection class properties don't get
serialized ?
Problem I have is not with the Event class but with Events class (the
collection). I thought Events class members will be also serialized.

It's quite basic what I am trying to do, it should work. If you have
any ideas pls help.

Thanks,
xke

On Oct 22, 10:06 pm, "Andrew Faust" <and...@.andrewfaust.comwrote:

Quote:

Originally Posted by

In your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?
>
--
Andrew Faust
andrew[at]andrewfaust.comhttp://www.andrewfaust.com
>
"xke" <xke...@.gmail.comwrote in message
>
news:1193083502.735588.136230@.e34g2000pro.googlegr oups.com...
>
>
>

Quote:

Originally Posted by

Why the collection property is not included in the ouput
serialization ?


>

Quote:

Originally Posted by

I have a custom generic collection (implements icollection): Events of
objects: Event.


>

Quote:

Originally Posted by

Event is a simple class exposing, let's say, one property: name


>

Quote:

Originally Posted by

Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class


>

Quote:

Originally Posted by

Events Implements ICollection
Public EventColor as string
......


>

Quote:

Originally Posted by

Everything works except when I save the xml file I'm expecting to get
smth like:


>

Quote:

Originally Posted by

<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>


>

Quote:

Originally Posted by

EVENTCOLOR attribute is not in the xml, any idea ?


>

Quote:

Originally Posted by

Thanks,
xke- Hide quoted text -


>
- Show quoted text -


Sorry. Misread your original post.

According to this article the Serializer only supports writing out the
actual objects contained in an ICollection and not the actual properties of
the collection itself.

http://www.diranieh.com/NETSerializ...rialization.htm
I would recommend a slight restructuring to something like this

class Events
{
public string EventColor;
private List<Eventm_Events;
public Event[] UpcomingEvents
{
get { return m_Events.ToArray(); }
set {
m_Events = new List<Event>();
m_Events.AddRange(value);
}
}
}

Then serialize the Events class.

"xke" wrote:

Quote:

Originally Posted by

Hi Andrew,
>
Yes, EventName gets serialized as member of Event class. Question
would be: why the parent collection class properties don't get
serialized ?
Problem I have is not with the Event class but with Events class (the
collection). I thought Events class members will be also serialized.
>
It's quite basic what I am trying to do, it should work. If you have
any ideas pls help.
>
Thanks,
xke
>
On Oct 22, 10:06 pm, "Andrew Faust" <and...@.andrewfaust.comwrote:

Quote:

Originally Posted by

In your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?

--
Andrew Faust
andrew[at]andrewfaust.comhttp://www.andrewfaust.com

"xke" <xke...@.gmail.comwrote in message

news:1193083502.735588.136230@.e34g2000pro.googlegr oups.com...

Quote:

Originally Posted by

Why the collection property is not included in the ouput
serialization ?


Quote:

Originally Posted by

I have a custom generic collection (implements icollection): Events of
objects: Event.


Quote:

Originally Posted by

Event is a simple class exposing, let's say, one property: name


Quote:

Originally Posted by

Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class


Quote:

Originally Posted by

Events Implements ICollection
Public EventColor as string
......


Quote:

Originally Posted by

Everything works except when I save the xml file I'm expecting to get
smth like:


Quote:

Originally Posted by

<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>


Quote:

Originally Posted by

EVENTCOLOR attribute is not in the xml, any idea ?


Quote:

Originally Posted by

Thanks,
xke- Hide quoted text -


- Show quoted text -


>
>
>


beautiful idea / will give it a try tomorrow

thanks,
xke

On Oct 23, 1:28 pm, Andrew Faust <afa...@.nospam.nospamwrote:

Quote:

Originally Posted by

Sorry. Misread your original post.
>
According to this article the Serializer only supports writing out the
actual objects contained in an ICollection and not the actual properties of
the collection itself.
>
http://www.diranieh.com/NETSerializ...rialization.htm
>
I would recommend a slight restructuring to something like this
>
class Events
{
public string EventColor;
private List<Eventm_Events;
public Event[] UpcomingEvents
{
get { return m_Events.ToArray(); }
set {
m_Events = new List<Event>();
m_Events.AddRange(value);
}
}
>
}
>
Then serialize the Events class.
>
>
>
"xke" wrote:

Quote:

Originally Posted by

Hi Andrew,


>

Quote:

Originally Posted by

Yes, EventName gets serialized as member of Event class. Question
would be: why the parent collection class properties don't get
serialized ?
Problem I have is not with the Event class but with Events class (the
collection). I thought Events class members will be also serialized.


>

Quote:

Originally Posted by

It's quite basic what I am trying to do, it should work. If you have
any ideas pls help.


>

Quote:

Originally Posted by

Thanks,
xke


>

Quote:

Originally Posted by

On Oct 22, 10:06 pm, "Andrew Faust" <and...@.andrewfaust.comwrote:

Quote:

Originally Posted by

In your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?


>

Quote:

Originally Posted by

Quote:

Originally Posted by

--
Andrew Faust
andrew[at]andrewfaust.comhttp://www.andrewfaust.com


>

Quote:

Originally Posted by

Quote:

Originally Posted by

"xke" <xke...@.gmail.comwrote in message


>

Quote:

Originally Posted by

Quote:

Originally Posted by

>news:1193083502.735588.136230@.e34g2000pro.googlegr oups.com...


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Why the collection property is not included in the ouput
serialization ?


>

Quote:

Originally Posted by

Quote:

Originally Posted by

I have a custom generic collection (implements icollection): Events of
objects: Event.


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Event is a simple class exposing, let's say, one property: name


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Events Implements ICollection
Public EventColor as string
......


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Everything works except when I save the xml file I'm expecting to get
smth like:


>

Quote:

Originally Posted by

Quote:

Originally Posted by

<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>


>

Quote:

Originally Posted by

Quote:

Originally Posted by

EVENTCOLOR attribute is not in the xml, any idea ?


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Thanks,
xke- Hide quoted text -


>

Quote:

Originally Posted by

Quote:

Originally Posted by

- Show quoted text -- Hide quoted text -


>
- Show quoted text -