Which code segment should you use?

You create an application to send a message by e-mail. An SMTP server is available on the local subnet.
The SMTP server is named smtp. Domain.com.
To test the application, you use a source address, [email protected], and a target address, [email protected].
You need to transmit the e-mail message.
Which code segment should you use

You create an application to send a message by e-mail. An SMTP server is available on the local subnet.
The SMTP server is named smtp. Domain.com.
To test the application, you use a source address, [email protected], and a target address, [email protected].
You need to transmit the e-mail message.
Which code segment should you use

A.
MailAddress addrFrom = new MailAddress(“[email protected]”,”Me”);
MailAddress addrTo = new MailAddress(“[email protected]”,”You”);
MailMessage message = new MailMessage(addrFrom, addrTo);
message.Subject = “Greeting!”;
message.Body = “Test”;
message.Dispose();

B.
string strSmtpClient = smtp.certkiller.com”;
string strFrom = “[email protected]”;
string strTo = “[email protected]”;
String strSubject = “Greetings!”;
String strBody = “Test”;
MailMessage msg = new MailMessage(strFrom, strTo, strSubject, strSmtpClient);

C.
MailAddress addrFrom, = new MailAddress(“[email protected]”);
MailAddress addrTo, = new MailAddress(“[email protected]”);
MailAddress message = new MailMessage(addrFrom,addrTo);
message.Subject = “Greeting!”;
message.Body = “Test”;
SmtpClient client = new SmtpClient(“smtp.certkiller.com”);
client.Send(message);

D.
MailAddress addrFrom = new MailAdress(“[email protected]”,”Me”);
MailAddress addrTo = new MailAddress(“[email protected]”,”You”);
MailMessage message = new MailMessage(addrFrom,addrTo);
message.Subject = “Greeting!”;
message.Body = “Test”;
SocketInformation info = new SocketInformation();
Socket client = new Socket(info);
System.Text.ASCIIEncoding enc = new System.Test.ASCIIENcoding();
byte[] msgBytes = enc.GetBytes(message. ToString());
client.Send(msgBytes);

Explanation:
To Send a simple mail message construct a MailMessage object and a SmptClient object.
Call the SmtpClient.Send instance method supplying the MailMessage object as a parameter.
A creates a MailMessage but then destroys it.
B creates a MailMessage but then does not do anything with it.
D tries to do something with sockets, this is unnecessary because there is a SMTP server
available. The question implies delivering the mail via SMTP.



Leave a Reply 1

Your email address will not be published. Required fields are marked *


seenagape

seenagape

I choose C