Email from web

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I was using MailMessage object vs2003 to send email form my webform. In
vs2005 it says MailMessage is obsolete. What should I use instead? Could
someone please give me an example? My smtp server needs authentication
(user/pass).

Thanks

Regards
 
I am using below. Is there a simple replacement for this?

Thanks

Imports System.web.Mail

Dim Mailer As MailMessage

Mailer = New MailMessage
Mailer.From = "from addrewss here"
Mailer.To = "to address here"
Mailer.Subject = "Feedback via Web"
Mailer.Body = Str
Mailer.BodyFormat = MailFormat.Text
SmtpMail.SmtpServer = "smtp mail server"
SmtpMail.Send(Mailer)
 
The code from the blog is below:

You don't have the serv object (which is at the blog), so you'll have to
improvise.



string sBody = "This email was sent:" + Environment.NewLine
+ serv.SmtpServerName + Environment.NewLine + serv.SmtpUserName;
string toAddress = "(e-mail address removed)";
string emailSubject = "2.0 Test!";



System.Net.Mail.SmtpClient email = new
System.Net.Mail.SmtpClient();
email.Host = serv.SmtpServerName;

if (serv.PortNumber.Length > 0)
{
email.Port = Convert.ToInt32(serv.PortNumber);

}

switch (serv.AuthenicationMethod)
{
case AuthenticationType.None:
break;

case AuthenticationType.Basic:

email.DeliveryMethod =
System.Net.Mail.SmtpDeliveryMethod.Network;

email.UseDefaultCredentials = false;





email.Credentials = new
NetworkCredential(serv.SmtpUserName, serv.SmtpUserPassword);
break;

case AuthenticationType.SSL:

email.EnableSsl = true;

email.Credentials = new
NetworkCredential(serv.SmtpUserName, serv.SmtpUserPassword);

//email.DeliveryMethod =
System.Net.Mail.SmtpDeliveryMethod.Network ;

break;

}



System.Net.Mail.MailMessage mailMsg = new
System.Net.Mail.MailMessage(serv.DefaultFromAddress, toAddress,
emailSubject, sBody);


mailMsg.IsBodyHtml = true;


email.Send(mailMsg);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top