Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

Can anyone explain this email sending code to me.

$
0
0

Hi

I have received the responsibility of maintain and further development of a existing web application. For this reason I am studying the codes behind it. As I am a novice to VB.net I am struggling very hard. 

Below is the code of sending email . The code is working fine in its current area.  But In this code I don't see any smtp client credentials and  smtp port .  How this code is working without the client port and client credentials

Imports System.Web.Configuration
Imports System.Net
Imports System.Net.Mail

Public Sub Send()
Dim Message As New System.Net.Mail.MailMessage
With Message
.Subject = Me.Subject
.Body = Me.Body
.From = EmailStringToMailAddress(Me.MailFrom)

AddAddressString(Me.MailTo, .To)
AddAddressString(Me.MailCC, .CC)
AddAddressString(Me.MailBCC, .Bcc)
.IsBodyHtml = True
If Not IsNothing(Attachments) Then

If Attachments.Length > 0 Then

For Each FileName As String In Split(Attachments, ";")

FileName = Replace(FileName, "~/", System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath & "/")

If FileName.StartsWith("/") Then
FileName = System.Web.HttpContext.Current.Server.MapPath(FileName)
End If

Try
Message.Attachments.Add(New System.Net.Mail.Attachment(FileName))
Catch
System.Web.HttpContext.Current.Response.Write(FileName & " could not be found")
End Try

Next

End If

End If

End With

Try
Dim Client As New System.Net.Mail.SmtpClient

With Client

If WebConfigurationManager.AppSettings("smtpserver").Length > 0 Then

.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory
.PickupDirectoryLocation = "c:/outbox/"
.Host = WebConfigurationManager.AppSettings("smtpserver")

Else
.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.PickupDirectoryFromIis

End If

.Send(Message)

End With

Catch Ex As Exception

_error = Ex.Message

End Try

Dim Query As String = ""
Query &= vbCrLf & "IF @id != 0"
Query &= vbCrLf & "BEGIN"
Query &= vbCrLf & " UPDATE emaillog SET error=@error, mailfrom=@mailfrom, mailto=@mailto, mailcc=@mailcc, mailbcc=@mailbcc, subject=@subject, emailcontentid=@emailcontentid WHERE id=@id;"
Query &= vbCrLf & " SELECT @id;"
Query &= vbCrLf & "END"
Query &= vbCrLf & "ELSE"
Query &= vbCrLf & "BEGIN"
Query &= vbCrLf & " INSERT INTO emaillog (error, mailfrom, mailto, mailcc, mailbcc, subject, body, emailcontentid) VALUES (@error, @mailfrom, @mailto, @mailcc, @mailbcc, @subject, @body, @emailcontentid);"
Query &= vbCrLf & " SELECT SCOPE_IDENTITY();"
Query &= vbCrLf & "END"
_id = Core.DB.GetInteger(WebConfigurationManager.ConnectionStrings("logConnectionString").ConnectionString, Query, _
Core.DB.SIP("id", _id), _
Core.DB.SIP("error", _error), _
Core.DB.SIP("emailcontentid", Me.ContentID), _
Core.DB.SIP("mailfrom", IIf(IsNothing(Me.MailFrom) = True, "", Me.MailFrom)), _
Core.DB.SIP("mailto", IIf(IsNothing(Me.MailTo) = True, "", Me.MailTo)), _
Core.DB.SIP("mailcc", IIf(IsNothing(Me.MailCC) = True, "", Me.MailCC)), _
Core.DB.SIP("mailbcc", IIf(IsNothing(Me.MailBCC) = True, "", Me.MailBCC)), _
Core.DB.SIP("subject", IIf(IsNothing(Me.Subject) = True, "", Me.Subject)), _
Core.DB.SIP("body", IIf(IsNothing(Me.Body) = True, "", Me.Body)))
End Sub

I want to understand this code cause I want to implement this code in to the other web forms in the application as well.

I will really appreciate if you help me to understand this code.

Thanks


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>