Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Email.Attributes("type") = "email"
End Sub
Protected Sub ContactUsclick()
Try
If ctrlGoogleReCaptcha.Validate Then
Dim ID = System.Guid.NewGuid
Dim FullNameText = Trim(FullName.Value)
Dim CompanyNameText = Trim(CompanyName.Value)
Dim EmailText = Trim(Email.Value)
Dim PhoneText = Phone.Value
Dim SerialNumberText = SerialNumber.Value
Dim ProductLocationAddress = ProductLocation.Value
Dim CommentText = Trim(Comment.Value)
DataAccessLayer.DataAccess.InsertServiceRequest(ID, FullNameText, CompanyNameText, EmailText, _
PhoneText, SerialNumberText, ProductLocationAddress, CommentText)
Dim AttachmentList As New List(Of Attachment)
For Each UploadedFile As HttpPostedFile In FileUpload.PostedFiles
Dim ServiceQueueUniqueIdentifier = System.Guid.NewGuid
Dim strFileName As String = System.IO.Path.GetFileName(UploadedFile.FileName)
Dim attachment As New Attachment(UploadedFile.InputStream, strFileName)
AttachmentList.Add(attachment)
Dim fs As Stream = UploadedFile.InputStream
Dim br As New BinaryReader(fs)
'Dim bytes As Byte() = br.ReadBytes(fs.Length)
DataAccessLayer.DataAccess.InsertServiceRequestAttachments(ServiceQueueUniqueIdentifier, ID, UploadedFile.FileName, UploadedFile.ContentType, br.ReadBytes(fs.Length))
Next
Dim body As String = BusinessLogic.Utilities.MailingFunctions.FormatServiceRequestToXML(FullNameText, CompanyNameText, EmailText, PhoneText, _
SerialNumberText, ProductLocationAddress, CommentText, AttachmentList.Count)
BusinessLogic.Utilities.MailingFunctions.SendSMTPContactRequest("""Phiston Feedback Mailer""" & "<" & ConfigurationManager.AppSettings("ContactUSFromEmailAddress") & ">", _
"Shahrouz.ebadian@gmail.com", "Service Request Received", body, AttachmentList, Nothing)
'BusinessLogic.Utilities.MailingFunctions.SendSMTPContactRequest("""Phiston Feedback Mailer""" & "<" & ConfigurationManager.AppSettings("ContactUSFromEmailAddress") & ">", _
' ConfigurationManager.AppSettings("ServiceContactToEmailAddress"), "Service Request Received", body, AttachmentList, Nothing)
Response.Redirect("contactthanks.aspx")
Else
ErrorLbl.Visible = True
End If
Catch ex As Exception
Throw
End Try
End Sub
Public Shared Function FormatServiceRequestToXML(ByVal FullName As String, ByVal CompanyName As String, ByVal Email As String, ByVal Phone As String, _
ByVal Serial As String, ByVal ProductAddress As String, ByVal comment As String, ByVal AttachmentCount As Integer)
Try
Dim builder As StringBuilder = New StringBuilder
Dim body As String = ""
builder.Append("<table bgcolor='#33ffff' width='100%' border='1' cellpadding='0' cellspacing='0'>")
builder.Append("<tr>")
builder.Append("<td width='100%' align='center' colspan='2' bgcolor='#00bbff'>")
builder.Append("<B>Phiston Contact Us</B>")
builder.Append("</td>")
builder.Append("</tr>")
builder.Append("<tr>")
builder.Append("<td style='width: 20%'><B>Date</B></td>")
builder.Append("<td style='width: 80%'> ")
builder.Append(Now().ToLongDateString & " " & Now().ToLongTimeString)
builder.Append("</td>")
builder.Append("</tr>")
builder.Append("<tr>")
builder.Append("<td style='width: 20%'><B>DB Name</B></td>")
builder.Append("<td style='width: 80%'> ")
builder.Append(BusinessLogic.SystemInfo.SystemInformation.GetDBName)
builder.Append("</td>")
builder.Append("</tr>")
builder.Append("<tr>")
builder.Append("<td style='width: 100%' align='center' colspan='2' bgcolor='#00bbff'><B>Information</B></td>")
builder.Append("</tr>")
builder.Append("<tr>")
builder.Append("<td style='width: 20%' align='left'><B>Full Name</B></td>")
builder.Append("<td style='width: 80%' align='left'>" & FullName & "</td>")
builder.Append("</tr>")
builder.Append("<tr>")
builder.Append("<td style='width: 20%' align='left'><B>Company Name</B></td>")
builder.Append("<td style='width: 80%' align='left'>" & CompanyName & "</td>")
builder.Append("</tr>")
builder.Append("<tr>")
builder.Append("<td style='width: 20%' align='left'><B>Email</B></td>")
builder.Append("<td style='width: 80%' align='left'>" & Email & "</td>")
builder.Append("</tr>")
builder.Append("<tr>")
builder.Append("<td style='width: 20%' align='left'><B>Phone</B></td>")
builder.Append("<td style='width: 80%' align='left'>" & Phone & "</td>")
builder.Append("</tr>")
builder.Append("<tr>")
builder.Append("<td style='width: 20%' align='left'><B>Serial #</B></td>")
builder.Append("<td style='width: 80%' align='left'>" & Serial & "</td>")
builder.Append("</tr>")
builder.Append("<tr>")
builder.Append("<td style='width: 20%' align='left'><B>Product Address</B></td>")
builder.Append("<td style='width: 80%' align='left'>" & ProductAddress & "</td>")
builder.Append("</tr>")
builder.Append("<tr>")
builder.Append("<td style='width: 20%' align='left'><B>Comment</B></td>")
builder.Append("<td style='width: 80%' align='left'>" & comment & "</td>")
builder.Append("</tr>")
builder.Append("<tr>")
builder.Append("<td style='width: 20%' align='left'><B>Files Attached</B></td>")
builder.Append("<td style='width: 80%' align='left'>" & AttachmentCount & "</td>")
builder.Append("</tr>")
Return builder.ToString
Catch e As Exception
Throw
End Try
End Function
Public Shared Sub SendSMTPContactRequest(ByVal strFrom As String, ByVal strTo As String, ByVal strSubject As String, ByVal strBody As String, _
ByVal Attachments As List(Of Attachment), ByVal CC As String)
Try
Dim insMail As New MailMessage(New MailAddress(strFrom), New MailAddress(strTo))
insMail.Priority = MailPriority.High
insMail.IsBodyHtml = True
With insMail
.Subject = strSubject
.Body = strBody
If Not (IsNothing(CC)) Then
.CC.Add(New MailAddress(CC))
End If
If Not IsNothing(Attachments) AndAlso Attachments.Count <> 0 Then
For i As Integer = 0 To Attachments.Count - 1
.Attachments.Add(Attachments(i))
Next
End If
End With
Dim smtp As New System.Net.Mail.SmtpClient
smtp.EnableSsl = False
smtp.Port = ConfigurationManager.AppSettings("SmtpPort")
smtp.Host = ConfigurationManager.AppSettings("SmtpHost")
smtp.Credentials = New System.Net.NetworkCredential(ConfigurationManager.AppSettings("ContactUsFromEmailAddress"), ConfigurationManager.AppSettings("ContactUSFromEmailPassword"))
smtp.Send(insMail)
Catch e As Exception
Throw
End Try
End Sub