How to use authentication while sending mails using SMTP with ASP.NET. |
| | | | Submitted on: 11/5/2003 1:41:55 PM
By: Kaustav N
Level: Beginner User Rating: Unrated Compatibility:C#, VB.NET, ASP.NET
Users have accessed this article 579 times. | (About the author) |
| | This article demonstrates how to authenticate a SMTP server in an ASP.NET application. | |
|
Terms of Agreement:
By using this article, you agree to the following terms...
1) You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description. |
Authenticate a SMTP Server in ASP.NET -- By Kaustav Neogy
In .NET we can use the
System.Web.Mail Namespace to send mails. The SMTPMail Class provides
properties and methods for sending messages using the Collaboration Data
Objects for Windows 2000 (CDOSYS) message component. However there exists no
direct way to use authentication with a SMTP Server. Here’s a quick
workaround to it.
|
|
|
Code:
|
|
Public Sub
Send_Mail_With_Auth(ByVal szTo As String, ByVal szFrom As String, ByVal
szSubject As String, ByVal szBody As String)
Dim myMsg
Dim myConfig
Dim Flds
Const cdoSendUsingPort = 2
Const cdoBasic As Integer = 1
myMsg = CreateObject("CDO.Message")
myConfig = CreateObject("CDO.Configuration")
Flds = myConfig.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") =
cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "your_smtp_server"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")
= 10
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") =
"username"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") =
"password"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") =
cdoBasic
.Update()
End With
With myMsg
.Configuration = myConfig
.To = szTo
.From = szFrom
.Subject = szSubject
.HTMLBody = szBody
.Send()
End With
myMsg = Nothing
myConfig = Nothing
Flds = Nothing
End Sub |
|
| |
|
Report Bad Submission |
|
|
Your Vote! |
See Voting Log |
|
Other User Comments |
11/12/2003 12:00:16 PM: excellent ! super, yo usave my life :)
|
|
Add Your Feedback! |
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.
NOTICE: The author of this article has been kind enough to share it with you. If you have a criticism, please state it politely or it will be deleted.
For feedback not related to this particular article, please click here. |
|