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 WithMailObj.Send(msg)
Regards
Hi,
Any question about Sending Mail may be answered at this website:
http://www.systemnetmail.com/
Good luck!
0 comments:
Post a Comment