ARTICLE

Send email via SMTP Server .NET 2.0

Posted by Yildirim Kocdag Articles | ASP.NET using VB.NET May 23, 2007
Send email via SMTP Server .NET Framework 2.0.
 
Reader Level:

One of the most common ways for sending email is using SMTP Server Machine. Firstly, System.Web.Email library should be imported to project.

Imports System.Web.Mail

Mail Message Object Type will be included to your code via this library. Mail Message is an object type which is a parameter of SmtpMail.Send function,

   Dim Mail As MailMessage

     Mail = New MailMessage

     Mail.From = "ykocdag80@yahoo.com"

     Mail.To = "ykocdag80@yahoo.com"

     Mail.Subject = "Mail Subject"

     Mail.Body = "Mail Body "

     Mail.BodyFormat = MailFormat.Html

     Mail.BodyEncoding = System.Text.Encoding.UTF8

After the MailMessage is configured, SMTP Server Machine name should be set,

SmtpMail.SmtpServer = "SMTPMachineName"

The last step in sending email,

 SmtpMail.Send(Mail)

 

Login to add your contents and source code to this article
share this article :
post comment
 

Sorry My code is as follows: Dim client = New System.Net.Mail.SmtpClient() client.Port = dsPkaur.Tables("smtp").Rows(0).Item("smtpport").ToString client.Host = dsPkaur.Tables("smtp").Rows(0).Item("smtphost").ToString Dim Msg As New MailMessage() Msg.From = New MailAddress("se.chandrakar@gmail.com") Msg.To.Add("pkaursikhni@gmail.com") Msg.CC.Add("pkaursikhni@gmail.com") Msg.Bcc.Add("pkaursikhni@gmail.com") Msg.Subject = "SubjectOfTheMailString" Msg.Body = "BodyOfTheMailString" Msg.IsBodyHtml = True Msg.BodyEncoding = System.Text.Encoding.UTF8 client.Send(Msg) It gives me Exception "Mailbox name not allowed. The server response was: Sorry, your envelope sender is in my badmailfrom list." will you clear it? Thanks. Parkash

Posted by Parkash Kaur Feb 18, 2011

Many email servers will reject email if the sending site address is not a registered email server.  What other code must be added to do this?

Posted by Patrick Thomas Nov 27, 2009

Hi Guys, I having problem attached multiple files in the folder  whether the extension *.txt, *.pdf ect.  I need help!  Please response

Minh

Posted by Minh Tang Oct 12, 2009
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
Become a Sponsor