Send email thru ASP.NET with SMTP Auth
Dear Expert,
I wrote below codes for sending email using ASP.NET.. but my SMTP server requires authentication, please help ..
Imports System.Net.Mail
...
...
...
Try
Dim SendFrom As MailAddress = New MailAddress(mFromAddr)
Dim SendTo As MailAddress = New MailAddress(pTo)
Dim MyMessage As MailMessage = New MailMessage(SendFrom, SendTo)
MyMessage.Subject = pSubject
MyMessage.Body = pBody & vbCrLf & NoReply_Note
Dim mAttachment As String = ""
Dim attachFile As New Attachment(pAttachment)
MyMessage.Attachments.Add(attachFile)
Dim emailClient As New SmtpClient(mSMTP)
emailClient.Send(MyMessage)
...
...
Catch ex As Exception
...
End Try
Thanks & Regards
Winanjaya
Re: Send email thru ASP.NET with SMTP Auth
VB Code:
Dim oEmail as New Net.Mail.MailMessage()
Dim oSmtp as New Net.Mail.SmtpClient
oSmtp.Host = "mail.test.com"
'This object stores the authentication values
Dim basicAuthenticationInfo As New System.Net.NetworkCredential()
basicAuthenticationInfo.UserName = "username"
basicAuthenticationInfo.Password = "password"
oSmtp.UseDefaultCredentials = False
oSmtp.Credentials = basicAuthenticationInfo
oEmail.Subject = "mailSubject"
oEmail.Body = "mailBody"
'send the eMail
oSmtp.Send(oEmail)
HTH
HoraShadow