ASP vbscript email form - only send fields with value - forms
This is the ASP code to send email..
<%
'declare variables
Dim EmailFrom
Dim EmailTo
Dim Subject
Dim DealerName
Dim DealerNumber
Dim InvoiceNumber
Dim PONumber
Dim InvoiceDate
Dim ModelNumber
Dim SerialNumber
Dim ConditionofUnit
Dim ReasonforRMA
Dim OtherText
Dim ModelNumber2
Dim SerialNumber2
Dim ConditionofUnit2
Dim ReasonforRMA2
Dim OtherText2
Dim ModelNumber3
Dim SerialNumber3
Dim ConditionofUnit3
Dim ReasonforRMA3
Dim OtherText3
Dim ModelNumber4
Dim SerialNumber4
Dim ConditionofUnit4
Dim ReasonforRMA4
Dim OtherText4
Dim ModelNumber5
Dim SerialNumber5
Dim ConditionofUnit5
Dim ReasonforRMA5
Dim OtherText5
Dim ModelNumber6
Dim SerialNumber6
Dim ConditionofUnit6
Dim ReasonforRMA6
Dim OtherText6
Dim ModelNumber7
Dim SerialNumber7
Dim ConditionofUnit7
Dim ReasonforRMA7
Dim OtherText7
Dim ModelNumber8
Dim SerialNumber8
Dim ConditionofUnit8
Dim ReasonforRMA8
Dim OtherText8
Dim ModelNumber9
Dim SerialNumber9
Dim ConditionofUnit9
Dim ReasonforRMA9
Dim OtherText9
Dim ModelNumber10
Dim SerialNumber10
Dim ConditionofUnit10
Dim ReasonforRMA10
Dim OtherText10
' get posted data into variables
EmailFrom = Trim(Request.Form("EmailFrom"))
EmailTo = "ouremail#domain.com"
Subject = "my subject"
DealerName = Trim(Request.Form("DealerName"))
DealerNumber = Trim(Request.Form("DealerNumber"))
InvoiceNumber = Trim(Request.Form("InvoiceNumber"))
PONumber = Trim(Request.Form("PONumber"))
InvoiceDate = Trim(Request.Form("InvoiceDate"))
ModelNumber = Trim(Request.Form("ModelNumber"))
SerialNumber = Trim(Request.Form("SerialNumber"))
ConditionofUnit = Trim(Request.Form("ConditionofUnit"))
ReasonforRMA = Trim(Request.Form("ReasonforRMA"))
OtherText = Trim(Request.Form("OtherText"))
ModelNumber2 = Trim(Request.Form("ModelNumber2"))
SerialNumber2 = Trim(Request.Form("SerialNumber2"))
ConditionofUnit2 = Trim(Request.Form("ConditionofUnit2"))
ReasonforRMA2 = Trim(Request.Form("ReasonforRMA2"))
OtherText2 = Trim(Request.Form("OtherText2"))
ModelNumber3 = Trim(Request.Form("ModelNumber3"))
SerialNumber3 = Trim(Request.Form("SerialNumber3"))
ConditionofUnit3 = Trim(Request.Form("ConditionofUnit3"))
ReasonforRMA3 = Trim(Request.Form("ReasonforRMA3"))
OtherText3 = Trim(Request.Form("OtherText3"))
ModelNumber4 = Trim(Request.Form("ModelNumber4"))
SerialNumber4 = Trim(Request.Form("SerialNumber4"))
ConditionofUnit4 = Trim(Request.Form("ConditionofUnit4"))
ReasonforRMA4 = Trim(Request.Form("ReasonforRMA4"))
OtherText4 = Trim(Request.Form("OtherText4"))
ModelNumber5 = Trim(Request.Form("ModelNumber5"))
SerialNumber5 = Trim(Request.Form("SerialNumber5"))
ConditionofUnit5 = Trim(Request.Form("ConditionofUnit5"))
ReasonforRMA5 = Trim(Request.Form("ReasonforRMA5"))
OtherText5 = Trim(Request.Form("OtherText5"))
ModelNumber6 = Trim(Request.Form("ModelNumber6"))
SerialNumber6 = Trim(Request.Form("SerialNumber6"))
ConditionofUnit6 = Trim(Request.Form("ConditionofUnit6"))
ReasonforRMA6 = Trim(Request.Form("ReasonforRMA6"))
OtherText6 = Trim(Request.Form("OtherText6"))
ModelNumber7 = Trim(Request.Form("ModelNumber7"))
SerialNumber7 = Trim(Request.Form("SerialNumber7"))
ConditionofUnit7 = Trim(Request.Form("ConditionofUnit7"))
ReasonforRMA7 = Trim(Request.Form("ReasonforRMA7"))
OtherText7 = Trim(Request.Form("OtherText7"))
ModelNumber8 = Trim(Request.Form("ModelNumber8"))
SerialNumber8 = Trim(Request.Form("SerialNumber8"))
ConditionofUnit8 = Trim(Request.Form("ConditionofUnit8"))
ReasonforRMA8 = Trim(Request.Form("ReasonforRMA8"))
OtherText8 = Trim(Request.Form("OtherText8"))
ModelNumber9 = Trim(Request.Form("ModelNumber9"))
SerialNumber9 = Trim(Request.Form("SerialNumber9"))
ConditionofUnit9 = Trim(Request.Form("ConditionofUnit9"))
ReasonforRMA9 = Trim(Request.Form("ReasonforRMA9"))
OtherText9 = Trim(Request.Form("OtherText9"))
ModelNumber10 = Trim(Request.Form("ModelNumber10"))
SerialNumber10 = Trim(Request.Form("SerialNumber10"))
ConditionofUnit10 = Trim(Request.Form("ConditionofUnit10"))
ReasonforRMA10 = Trim(Request.Form("ReasonforRMA10"))
OtherText10 = Trim(Request.Form("OtherText10"))
Dim mail
Set mail = Server.CreateObject("CDONTS.NewMail")
mail.To = EmailTo
mail.BodyFormat = 0
mail.MailFormat = 0
mail.From = EmailFrom
mail.Subject = Subject
mail.Body = "This is an email generated." & "<br>" & "<br>" & _
"<b>Dealer Name: </b>" & DealerName & "<br>" & _
"<b>Dealer Number: </b>" & DealerNumber & "<br>" & _
"<b>Invoice Number: </b>" & InvoiceNumber & "<br>" & _
"<b>PO Number: </b>" & PONumber & "<br>" & _
"<b>Invoice Date: </b>" & InvoiceDate & "<br>" & _
"<b>------ ITEM 1 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText & "<br>" & _
"<b>------ ITEM 2 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber2 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber2 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit2 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA2 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText2 & "<br>" & _
"<b>------ ITEM 3 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber3 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber3 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit3 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA3 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText3 & "<br>" & _
"<b>------ ITEM 4 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber4 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber4 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit4 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA4 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText4 & "<br>" & _
"<b>------ ITEM 5 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber5 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber5 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit5 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA5 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText5 & "<br>" & _
"<b>------ ITEM 6 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber6 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber6 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit6 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA6 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText6 & "<br>" & _
"<b>------ ITEM 7 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber7 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber7 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit7 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA7 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText7 & "<br>" & _
"<b>------ ITEM 8 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber8 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber8 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit8 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA8 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText8 & "<br>" & _
"<b>------ ITEM 9 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber9 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber9 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit9 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA9 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText9 & "<br>" & _
"<b>------ ITEM 10 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber10 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber10 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit10 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA10 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText10 & "<br>"
mail.Send
' redirect to success page
Response.Redirect("complete.html")
%>
So as you can see instead of sending all 10 items in every email, does anyone know how I can only send the items that actually get filled out with values? Only filling out 1 item is required with the ability to do up to 10..
EDIT: I changed it to this:
Dim mail
Set mail = Server.CreateObject("CDONTS.NewMail")
mail.To = EmailTo
mail.BodyFormat = 0
mail.MailFormat = 0
mail.From = EmailFrom
mail.Subject = Subject
If Request.Form("ModelNumber2") <> "" Then
mail.Body = "This is an email generated." & "<br>" & "<br>" & _
"<b>Dealer Name: </b>" & DealerName & "<br>" & _
"<b>Dealer Number: </b>" & DealerNumber & "<br>" & _
"<b>Invoice Number: </b>" & InvoiceNumber & "<br>" & _
"<b>PO Number: </b>" & PONumber & "<br>" & _
"<b>Invoice Date: </b>" & InvoiceDate & "<br>" & _
"<b>------ ITEM 1 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText & "<br>" & _
"<b>------ ITEM 2 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber2 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber2 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit2 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA2 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText2 & "<br>"
ElseIf Request.Form("ModelNumber2") <> "" And Request.Form("ModelNumber3") <> "" Then
mail.Body = "This is an email generated." & "<br>" & "<br>" & _
"<b>Dealer Name: </b>" & DealerName & "<br>" & _
"<b>Dealer Number: </b>" & DealerNumber & "<br>" & _
"<b>Invoice Number: </b>" & InvoiceNumber & "<br>" & _
"<b>PO Number: </b>" & PONumber & "<br>" & _
"<b>Invoice Date: </b>" & InvoiceDate & "<br>" & _
"<b>------ ITEM 1 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText & "<br>" & _
"<b>------ ITEM 2 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber2 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber2 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit2 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA2 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText2 & "<br>" & _
"<b>------ ITEM 3 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber3 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber3 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit3 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA3 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText3 & "<br>"
'ElseIf Request.Form("ModelNumber4") = "" Then
'ElseIf Request.Form("ModelNumber5") = "" Then
'ElseIf Request.Form("ModelNumber6") = "" Then
'ElseIf Request.Form("ModelNumber7") = "" Then
'ElseIf Request.Form("ModelNumber8") = "" Then
'ElseIf Request.Form("ModelNumber9") = "" Then
'ElseIf Request.Form("ModelNumber10") = "" Then
Else
mail.Body = "This is an email generated." & "<br>" & "<br>" & _
"<b>Dealer Name: </b>" & DealerName & "<br>" & _
"<b>Dealer Number: </b>" & DealerNumber & "<br>" & _
"<b>Invoice Number: </b>" & InvoiceNumber & "<br>" & _
"<b>PO Number: </b>" & PONumber & "<br>" & _
"<b>Invoice Date: </b>" & InvoiceDate & "<br>" & _
"<b>------ ITEM 1 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText & "<br>"
End If
mail.Send
But when I fill out 3 items it still only sends the email for 2 items. What am I missing here?
I would reduce the amount of typing with a loop...
(easiest if you add the "1" to the end of the first set of fields)
Been a while since I did any Classic ASP but from memory this should work:
mail.Body = "This is an email generated." & "<br>" & "<br>" & _
"<b>Dealer Name: </b>" & DealerName & "<br>" & _
"<b>Dealer Number: </b>" & DealerNumber & "<br>" & _
"<b>Invoice Number: </b>" & InvoiceNumber & "<br>" & _
"<b>PO Number: </b>" & PONumber & "<br>" & _
"<b>Invoice Date: </b>" & InvoiceDate & "<br>"
for i = 1 to 10
if trim(Request.Form("ModelNumber" & cstr(i))) <> "" then
mail.Body += "<b>------ ITEM " & cstr(i) & " ------</b><br>" & _
"<b>Model Number: </b>" & trim(Request.Form("ModelNumber" & cstr(i)) & "<br>" & _
"<b>Serial Number: </b>" & trim(Request.form("SerialNumber" & cstr(i)) & "<br>" & _
...
end if
next
Related
Cannot send the emails through the ASP Form
I am unable to send the email through the form because of the following error. I assume that the form doesn't work because of the depricated CDO? I'm not sure, but also I am not sure how to fix this problem. CDO.Message.1 error '80040220' The "SendUsing" configuration value is invalid. /thankyou.asp, line 24 The Code <% Set objMail = Server.CreateObject("CDO.Message") objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost" objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objMail.Configuration.Fields.Update objMail.From = Request.Form("Email") ' change this to an email address objMail.To = "admin#domain.com" ' change this to your email address objMail.Subject = "name Questions/Comments" ' change this to your subject 'Set the e-mail body format (HTMLBody=HTML TextBody=Plain) 'Set the e-mail body format (HTMLBody=HTML TextBody=Plain) objMail.HTMLBody = "<font size=3 face=verdana>" objMail.HTMLBody = objMail.HTMLBody & "<strong>" & "From: " & "</strong>" & Request.form("Name") & "<br>" objMail.HTMLBody = objMail.HTMLBody & "<strong>" & "Email: " & "</strong>" & Request.Form("Email") & "<br>" objMail.HTMLBody = objMail.HTMLBody & "<strong>" & "Phone: " & "</strong>" & Request.Form("Phone") & "<br>" & "<br>" objMail.HTMLBody = objMail.HTMLBody & "<strong>" & "Questions/Comments: " & "</strong>" & "<br>" & Replace(Request.Form("Details"), vbCrLf, "<br />") & "<br>" & "<br>" & "</font>" 'objMail.HTMLBody = objMail.HTMLBody & "<em>" & "Sent at " & Now() & "</em>" & "</font>" objMail.Send() Set objMail = Nothing* %> I don't have the access to the physical server and I cannot change the permissions myself. http://blogs.msdn.com/b/akashb/archive/2010/05/24/error-cdo-message-1-0x80040220-the-quot-sendusing-quot-configuration-value-is-invalid-on-iis-7-5.aspx Any ideas how can I fix this piece of code to make it work again? I have tried this: http://forums.iis.net/t/1146477.aspx?The+SendUsing+configuration+value+is+invalid+ Changing SendUsing to 1. And setting up google snmp to send the emails without much results. Any information would be helpful.
replace your code with this: <% Set cdoConfiguration = Server.CreateObject("CDO.Configuration") With cdoConfiguration .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost" .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 .Fields.Update End With Dim tmpStr tmpStr = "" tmpStr = "<font size=""3"" face=""verdana"">" tmpStr = tmpStr & "<ul>" tmpStr = tmpStr & "<li><strong>" & "From: " & "</strong>: " & Request.form("Name") & "</li>" tmpStr = tmpStr & "<li><strong>" & "Email: " & "</strong>: " & Request.form("Email") & "</li>" tmpStr = tmpStr & "<li><strong>" & "Phone: " & "</strong>: " & Request.form("Phone") & "</li>" tmpStr = tmpStr & "<li><strong>Questions/Comments</strong>:<br/>" tmpStr = tmpStr & Replace(Request.Form("Details"), vbCrLf, "<br />") tmpStr = tmpStr & "</li>" tmpStr = tmpStr & "</ul>" tmpStr = tmpStr & "<p>Sent at " & Now() & "</p>" tmpStr = tmpStr & "</font>" Set newMailObj = Server.CreateObject("CDO.Message") newMailObj.Configuration = cdoConfiguration newMailObj.Subject = "name Questions/Comments" newMailObj.From = Request.Form("Email") newMailObj.To = "admin#domain.com" newMailObj.HTMLBody = tmpStr newMailObj.Send set newMailObj = nothing set cdoConfiguration = nothing %> and let us know if it works like that, cause if it does, your code (or at least the part you paste to us) is not correct... and, by the way, if you're using localhost I'm almost sure that the server configuration is not necessary... It is obligatory if you use a remote server like smtp.server.com
How to use multiple variables directly with CDOSYS parameters in Classic ASP
I am writing email sending code in Classic ASP using CDOSYS, but what i found when i try to write variables concatenation with CDOSYS parameters its gives me error. I could not write code in following way- mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "admin#" & website it givees me following error while execution - CDO.Message.1 error '80040213' while following code works fine as its having single variable- http://schemas.microsoft.com/cdo/configuration/sendusername") = websiteemail Note:- Reason to use in that way because my client having many sites and previously we used CDONTS and ASPEMAILS and it used to work fine.
Here is the function I created: function email(s_from,s_reply_to,s_recipients,s_bcc,s_subject,s_msg,s_type,s_msg_error_add,s_remote_host) if (s_msg_error_add<>"") then s_msg_error_add = "<hr>" & vbCrLf & s_msg_error_add if (s_remote_host="default") then s_remote_host = application("s_mail_server") if (s_remote_host="") then s_remote_host = "localhost" s_remote_host=lcase(s_remote_host) 's_recipients looks like "Scott <scott#domain.net>; Sue <andy#domain.net>" etc s_from = replace(s_from,","," ",1,-1,1) s_from = replace(s_from," "," ",1,-1,1) s_from = replace(s_from,"[","<",1,-1,1) s_from = replace(s_from,"]",">",1,-1,1) if (s_reply_to<>"") then s_reply_to = replace(s_reply_to,","," ",1,-1,1) s_reply_to = replace(s_reply_to," "," ",1,-1,1) s_reply_to = replace(s_reply_to,"[","<",1,-1,1) s_reply_to = replace(s_reply_to,"]",">",1,-1,1) end if s_recipients = replace(s_recipients,",",";",1,-1,1) s_recipients = replace(s_recipients," "," ",1,-1,1) s_recipients = replace(s_recipients,"[","<",1,-1,1) s_recipients = replace(s_recipients,"]",">",1,-1,1) if (s_bcc<>"") then s_bcc = replace(s_bcc,","," ",1,-1,1) s_bcc = replace(s_bcc," "," ",1,-1,1) s_bcc = replace(s_bcc,"[","<",1,-1,1) s_bcc = replace(s_bcc,"]",">",1,-1,1) end if err.clear Dim MailerConfig Dim Mailer Dim strRet dim sch strRet = "" sch = "http://schemas.microsoft.com/cdo/configuration/" Set MailerConfig = CreateObject("CDO.Configuration") Set Mailer = CreateObject("CDO.Message") With MailerConfig.Fields '.Item(sch & "sendusing") = 2 'send using port - if err then this is really "SendUsingMethod" '.Item(sch & "sendusingmethod") = 2 'send using port - if err then this is really "SendUsingMethod" .Item(sch & "smtpconnectiontimeout") = 900 '.Item(sch & "smtpauthenticate") = 1 'use basic (clear-text) authentication .Item(sch & "smtpserver") = s_remote_host '.Item(sch & "smtpserverport") = 25 '.Item(sch & "sendusername") = SMAUTHUSER '.Item(sch & "sendpassword") = SMAUTHPASS .Update End With Mailer.Configuration = MailerConfig 'Mailer.Fields(cdoImportance) = 1 'Mailer.Fields("urn:schemas:mailheader:X-MSMail-Priority") = 1 'Mailer.Fields("urn:schemas:mailheader:X-Mailer") = "" 'Mailer.Fields.Update '-- Set the Mail Properties 'on error resume next Mailer.From = s_from Mailer.To = s_recipients if (s_reply_to<>"" and s_reply_to<>"na") then Mailer.ReplyTo = s_reply_to b_redirect=false if (err.number<>0 and err.number<>13) then session("msg") = "Error in i_fn_email_cdo.asp line 72, Error: " & err.number & "<br>" & err.description if (b_redirect) then response.redirect ("error_report.asp?send_mail=yes") end if if (s_bcc<>"" AND s_bcc<>"na" AND s_bcc<>"n/a") then Mailer.BCC = s_bcc if (err.number<>0 and err.number<>13) then session("msg") = "Error in i_fn_email_cdo.asp line 79, Error: " & err.number & "<br>" & err.description if (b_redirect) then response.redirect ("error_report.asp?send_mail=yes") end if Mailer.Subject = s_subject if (err.number<>0 and err.number<>13) then session("msg") = "Error in i_fn_email_cdo.asp line 86, Error: " & err.number & "<br>" & err.description if (b_redirect) then response.redirect ("error_report.asp?send_mail=yes") end if if (s_type="html") then Mailer.AutoGenerateTextBody = True s_msg = replace(s_msg,vbCrLf,"<br>",1,-1,1) else Mailer.AutoGenerateTextBody = False end if if (err.number<>0 and err.number<>13) then session("msg") = "Error in i_fn_email_cdo.asp line 103, Error: " & err.number & "<br>" & err.description if (b_redirect) then response.redirect ("error_report.asp?send_mail=yes") end if Mailer.MimeFormatted = False if (err.number<>0 and err.number<>13) then session("msg") = "Error in i_fn_email_cdo.asp line 110, Error: " & err.number & "<br>" & err.description if (b_redirect) then response.redirect ("error_report.asp?send_mail=yes") end if if (s_type = "text") then Mailer.TextBody = fn_dirty(s_msg) else 's_msg_html = replace(s_msg,vbCrLf,"<br>",1,-1,1) s_msg_html = s_msg Mailer.HTMLBody = fn_dirty(s_msg_html) end if if (err.number<>0 and err.number<>13) then session("msg") = "Error in i_fn_email_cdo.asp line 123, Error: " & err.number & "<br>" & err.description if (b_redirect) then response.redirect ("error_report.asp?send_mail=yes") end if '-- Fire off the email message Mailer.Send if (err.number<>0 and err.number<>13) then Select Case err.Number Case -2147220973 strRet = " Failure to Send Report Message - Server Not Found" & vbCrLf & " Error: " & err.Number & " - " & err.Description Case -2147220975 strRet = " Failure to Send Report Message - Server Authentication Failed" & vbCrLf & " Error: " & err.Number & " - " & err.Description Case Else strRet = " Failure to Send Report Message - Error: " & err.Number & " - " & err.Description End Select msg = "<br>Error in i_fn_email_cdo.asp: " & strRet & "<br><br>" msg = msg & "remote host = " & s_remote_host & "<br>" s_from = replace(s_from,"<","[",1,-1,1) s_from = replace(s_from,">","]",1,-1,1) s_reply_to = replace(s_reply_to,"<","]",1,-1,1) s_reply_to = replace(s_reply_to,">","[",1,-1,1) s_recipients = replace(s_recipients,"<","[",1,-1,1) s_recipients = replace(s_recipients,">","]",1,-1,1) s_bcc = replace(s_bcc,"<","[",1,-1,1) s_bcc = replace(s_bcc,">","]",1,-1,1) msg = msg & "from = " & s_from & "<br>" msg = msg & "to = " & s_recipients & "<br>" msg = msg & "subject = " & s_subject & "<br>" msg = msg & "recipients = " & s_recipients & "<br><br>" if (s_type = "text") then msg = msg & s_msg else msg = msg & s_msg_html end if msg = msg & "<br>" msg = msg & s_msg_error_add session("msg") = msg Set Mailer = Nothing set MailerConfig = nothing if (b_redirect) then response.redirect ("error_report.asp?send_mail=yes") end if Set Mailer = Nothing set MailerConfig = nothing email = true end function
ASP.NET SOAP Request
I am successfully sending a soap request to a payment gateway as follows. But cannot obtain the response from the gateway in a meaningful manner (just string of values using the last line of code shown below). What is the best approach? Thanks. Dim manualWebClient As New System.Net.WebClient() manualWebClient.Headers.Add("Content-Type", "text/xml; charset=utf-8") Dim bytArguments As Byte() = System.Text.Encoding.ASCII.GetBytes( _ "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & System.Environment.NewLine & _ " <soap:Body>" & System.Environment.NewLine & _ " <CrossReferenceTransaction xmlns=""https://www.blahblah.net/"">" & System.Environment.NewLine & _ " <PaymentMessage>" & System.Environment.NewLine & _ " <MerchantAuthentication MerchantID=""blahblah"" Password=""blahblah"" />" & System.Environment.NewLine & _ " <TransactionDetails Amount=""5000"" CurrencyCode=""826"">" & System.Environment.NewLine & _ " <MessageDetails TransactionType=""COLLECTION"" NewTransaction=""TRUE"" CrossReference=""140519132324310202778936"" />" & System.Environment.NewLine & _ " <OrderID>order12345</OrderID>" & System.Environment.NewLine & _ " <OrderDescription>Monthly Subscription</OrderDescription>" & System.Environment.NewLine & _ " <TransactionControl>" & System.Environment.NewLine & _ " <EchoCardType>TRUE</EchoCardType>" & System.Environment.NewLine & _ " <EchoAVSCheckResult>TRUE</EchoAVSCheckResult>" & System.Environment.NewLine & _ " <EchoCV2CheckResult>TRUE</EchoCV2CheckResult>" & System.Environment.NewLine & _ " <EchoAmountReceived>TRUE</EchoAmountReceived>" & System.Environment.NewLine & _ " <DuplicateDelay>60</DuplicateDelay>" & System.Environment.NewLine & _ " </TransactionControl>" & System.Environment.NewLine & _ " </TransactionDetails>" & System.Environment.NewLine & _ " </PaymentMessage>" & System.Environment.NewLine & _ " </CrossReferenceTransaction>" & System.Environment.NewLine & _ " </soap:Body>" & System.Environment.NewLine & _ "</soap:Envelope>") Dim bytRetData As Byte() = manualWebClient.UploadData("https://blahblahblah.com:4430", "POST", bytArguments) Response.Write(System.Text.Encoding.ASCII.GetString(bytRetData))
How to reconcile the lack of Macros in Visual Studio 2012
My organization has extremely restrictive and rigid rules our code must comply with in order to obtain certification and accreditation. For the last decade or so we have developed nearly a hundred VS macros that format code, generate comments blocks, enforce style rules, etc. Our macros are not the kind you record some mouse movements; they all depend on the EnvDTE* VS automation objects. With VS 2012 dropping macros we are at a loss as to whether or not we will even be able to upgrade, without imposing a drastic impact on the team. I am aware that the direction Microsoft is going is the VS Addins route and I am willing to investigate that route but I am having trouble finding code samples or documentation on how a VS Add-In can interact with the active code file in Visual Studio. For example, here is a macro we use all the time that applies our Try wrapper design pattern to all methods that are capable of throwing unhandled exceptions ''' <summary> ''' Wraps active method in Try* access wrappers. ''' </summary> Sub InsertSingleMethodTryWrappers() Dim textSelection As TextSelection Dim codeElement As CodeElement textSelection = DTE.ActiveWindow.Selection DTE.UndoContext.Open("Generate Try Wrappers") 'Allow for single Undo operation to rollback all changes Try codeElement = textSelection.ActivePoint.CodeElement(vsCMElement.vsCMElementFunction) If Not (codeElement Is Nothing) Then Dim textSelection2 As TextSelection Dim codeFunction As CodeFunction 'Dim codeFunction2 As CodeFunction2 Dim editPoint As EditPoint Dim codeParameter As CodeParameter Dim parameters As CodeElements Dim codeElement2 As CodeElement Dim isVirtual As Boolean = False Dim strVirtual As String = String.Empty Dim strTypeName As String = String.Empty '' Cast the codeElement to codeFunction object codeFunction = codeElement '' Move cursor to the start of the method textSelection.MoveToPoint(codeFunction.GetStartPoint(vsCMPart.vsCMPartHeader)) '' Should be able to use codeFunction.Kind.ToString to retrieve the function type '' vsCMFunctionVirtual if the method is virtual but there is a bug in the API '' that returns vsCMFunctionFunction even if the function is virtual (C# parsing bug?) '' '' vsCMFunction Type '' http://msdn.microsoft.com/en-us/library/envdte.vscmfunction(v=vs.80).aspx '' '' This frustrating bug means that we have to parse the header to determine if virtual textSelection.EndOfLine(True) If (textSelection.Text.IndexOf("virtual") > 0) Then isVirtual = True strVirtual = " virtual" End If textSelection.StartOfLine() '' Try not to screw up comments and attributes editPoint = GetNoneCommentOrAttribHeaderEditPoint(textSelection) If editPoint Is Nothing Then MsgBox("Could not find a line above the method that isn't a comment or attribute", _ MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Error") Exit Sub End If '' Create an EditPoint to inject Try* methods 'editPoint = textSelection.TopPoint.CreateEditPoint() 'editPoint.LineUp() 'Move up 1 line editPoint.EndOfLine() 'Go to end of line above signature editPoint.Insert(Environment.NewLine) 'Insert blank line for cleanliness editPoint.Insert(Environment.NewLine) 'Insert blank line for cleanliness editPoint.LineUp() 'Move up 1 line parameters = codeFunction.Parameters Dim strAccess As String : strAccess = GetAccessModifierString(codeFunction.Access) 'Access Modifier Dim strName As String : strName = codeElement.Name 'Member Name Dim strType As String : strType = codeFunction.Type.AsString 'Type Name '' Get the un-qualified object name If (strType.IndexOf(".") > 0) Then Dim arrType() As String = strType.Split(".") strTypeName = arrType(arrType.Length - 1) Else strTypeName = strType End If ''' Create parameter type/name arrayList Dim arrParams As System.Collections.ArrayList arrParams = New System.Collections.ArrayList() For Each codeElement2 In parameters codeParameter = codeElement2 arrParams.Add(codeParameter.Type.AsString.Trim & " " & codeParameter.Name.Trim & ", ") Next Dim strParams As String Dim strParamNames As String '' Capture a string with parameter names and types and one just of names For Each strParam As String In arrParams strParams += strParam strParamNames += strParam.Split(" ")(1) Next '' Trim excess comma for members of type void If strType = "void" Then If Not String.IsNullOrEmpty(strParams) Then If strParams.TrimEnd.EndsWith(",") Then strParams = strParams.TrimEnd() strParams = strParams.Remove(strParams.Length - 1, 1) End If End If End If '' -- Try* swallow methods -- '' we don't care what the exception is, we just want to know success or failure Dim strTrySwallowSignature As String Dim strTrySwallowBody As String Dim strTryOutParams As String Dim strOutDef As String Dim strOutSig As String '' Members of type 'void' get no out parameters If Not strType = "void" Then strTryOutParams = "out " & strTypeName & " outObjType" strOutDef = "outObjType = null;" strOutSig = " out outObjType," End If strTrySwallowSignature = vbTab & vbTab & strAccess & strVirtual & " bool Try" & strName & "(" & strParams & strTryOutParams & ")" strTrySwallowBody = vbCrLf & vbTab & vbTab & "{" _ & vbCrLf & vbTab & vbTab & vbTab & "Exception exception;" _ & vbCrLf & vbTab & vbTab & vbTab & strOutDef _ & vbCrLf & vbTab & vbTab & vbTab & "return Try" & strName & "(" & strParamNames & strOutSig & " out exception);" _ & vbCrLf & vbTab & vbTab & "}" '' -- Try* re-throw methods -- '' We want to know success or failure as well as the exception if it failed Dim strTryReThrowSignature As String Dim strTryReThrowBody As String '' Members of type 'void' only get out exception parameter If Not strType = "void" Then strTryOutParams = "out " & strTypeName & " outObjType, out Exception exception" 'strOutDef = "outObjType = new " & strTypeName & "();" strOutDef = "outObjType = null;" Else strTryOutParams = "out Exception exception" End If strTryReThrowSignature = vbTab & vbTab & strAccess & strVirtual & " bool Try" & strName & "(" & strParams & strTryOutParams & ")" strTryReThrowBody = vbCrLf & vbTab & vbTab & "{" _ & vbCrLf & vbTab & vbTab & vbTab & "bool result = false;" _ & vbCrLf & vbTab & vbTab & vbTab & "exception = null;" _ & vbCrLf & vbTab & vbTab & vbTab & strOutDef _ & vbCrLf & vbTab & vbTab & vbTab & "try" _ & vbCrLf & vbTab & vbTab & vbTab & "{" _ & vbCrLf & vbTab & vbTab & vbTab & vbTab & "// insert code here " _ & vbCrLf & vbTab & vbTab & vbTab & vbTab & "//result = true; " _ & vbCrLf & vbTab & vbTab & vbTab & vbTab & "throw new NotImplementedException();" _ & vbCrLf & vbTab & vbTab & vbTab & "}" _ & vbCrLf & vbTab & vbTab & vbTab & "catch (Exception e)" _ & vbCrLf & vbTab & vbTab & vbTab & "{" _ & vbCrLf & vbTab & vbTab & vbTab & vbTab & "exception = e;" _ & vbCrLf & vbTab & vbTab & vbTab & "}" _ & vbCrLf & vbTab & vbTab & vbTab & "return result;" _ & vbCrLf & vbTab & vbTab & "}" editPoint.Insert(strTrySwallowSignature) editPoint.Insert(strTrySwallowBody) editPoint.Insert(vbCrLf & vbCrLf) editPoint.Insert(strTryReThrowSignature) editPoint.Insert(strTryReThrowBody) editPoint.Insert(vbCrLf) End If Catch Ex As Exception MsgBox(Ex.Message) Finally DTE.UndoContext.Close() End Try End Sub Can someone direct me to how a VS 2012 Add-in can manipulate the active/open code file (using EnvDTE* or whatever object model is available for 2012)?
Well that turned out to be really simple. Turns out the Macro object model is part of the VS model so no problem. http://msdn.microsoft.com/en-us/library/za2b25t3%28v=vs.110%29.aspx http://msdn.microsoft.com/en-us/library/ms228776.aspx I should have know Microsoft wouldn't have left us Macro-dependant developers out in the cold like that!
How to fix error in Sending Email in classic .asp page?
Inquiry.asp page call from inquiry.html with method="post" Inquiry.asp page code <% message="" message=message & "Name : " & Request.Form("txtName") & vbcrlf message=message & "Designation : " & Request.Form("txtDesignation") & vbcrlf message=message & "Organization : " & Request.Form("txtOrganization") & vbcrlf message=message & "Address : " & Request.Form("txtAddress") & vbcrlf message=message & "City : " & Request.Form("txtCity") & vbcrlf message=message & "State : " & Request.Form("txtState") & vbcrlf message=message & "Country : " & Request.Form("cmbCountry") & vbcrlf message=message & "Phone : " & Request.Form("txtPhone") & vbcrlf message=message & "Email : " & Request.Form("txtEmail") & vbcrlf message=message & "Fax : " & Request.Form("txtFax") & vbcrlf message=message & "Category : " & Request.Form("cmbCategory") & vbcrlf message=message & "Query : " & Request.Form("txtQuery") & vbcrlf message=message & "Product of Interest : " & Request.Form("txtgpo") & vbcrlf message=message & "Product of Interest : " & Request.Form("txtgta") & vbcrlf message=message & "Product of Interest : " & Request.Form("txtgpu") & vbcrlf message=message & "Product of Interest : " & Request.Form("txtsw") & vbcrlf message=message '& "**********************************************************" set objmail=server.createobject("CDONTS.NewMail") objmail.bodyformat = 0 objmail.to = "info#ankurscientific.com" objmail.To = "abc#gmail.com" 'objmail.From = Request.Form("txtemail") objmail.From = "info#domain.com" objmail.Subject="Enquiry" objmail.BodyFormat = 1 objmail.Body=message objmail.Send set objmail=nothing %> I getting error: '80070003' /sendmail.asp, line no:xx
This is an explanation and solution to your problem: http://support.microsoft.com/kb/238956