I need to send e-mail created with CKEditor and sending it using phpmailer. I use the following code:
$to =$_POST["toEmail"];
$subject=$_POST["emailSubj"];
$from=$_POST["fromEmail"];
$body= $_POST["editor1"];
$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->From = "example#example.com";
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->WordWrap = 50;
$mail->AltBody="Hello, my friend! \n\n This message uses HTML entities, but you prefer plain text !";
if($mail->Send())
{
echo "Message Send Successfully";
}
but i recieved the text like hi etc.. or some time plain text not the html email.
What should I need to do to receive html email.
$mail->IsHTML(true); this line itself ensures that the body will be sent out as an HTML.
1) Try sending a normal HTML formatted string as an email and check if it works.
2) echo the $body on the browser and see if it comes up properly.
3) Not really sure, but this must be an issue with the HTML entities getting encoded so check on those lines.
Related
Every day, I need to check my visa application status on the USCIS website (https://egov.uscis.gov/casestatus/landing.do). Since manually doing it gets cumbersome, I created automation in UIPath to run every few hours and email me if the status changed. However, it still needs to open the browser, navigate to the page, read the result, etc.
Is there a better way of going about this?
I tried finding if USCIS has any API that I could programmatically call, but there doesn't seem to be any. I looked at the page and found that the text box for the receipt number has the following HTML:
<input id="receipt_number" name="appReceiptNum" type="text" class="form-control textbox" maxlength="13"/>
So, from Postman, I tried firing a GET request:
GET https://egov.uscis.gov/casestatus/landing.do?receipt_number=XXXXXXXX
where XXXXXXXX would be my actual application number. But this didn't work and it just returned the main page. I tried switching it to a POST, but that didn't work either and returned the same result. On further inspection, I realized that the actual result page has a different URL, so I tried GET and POST both, on the result URL:
GET https://egov.uscis.gov/casestatus/mycasestatus.do?receipt_number=XXXXXXXX
This gets me a page telling me that there were validation errors and they didn't recognize.
Went back to the manual process to see if I was missing anything. The result page URL has a format
https://egov.uscis.gov/casestatus/mycasestatus.do?JSESSIONID=ZZZZZZZZZ
where ZZZZZZZZZ is the value of JSESSIONID cookie set during the landing page. So I changed my process to:
Send a GET request to the landing page (https://egov.uscis.gov/casestatus/landing.do)
Copy the value of JSESSIONID cookie from the response and set that as a query parameter in the request to the result page (https://egov.uscis.gov/casestatus/mycasestatus.do), while sending receipt_number as the payload in a POST request
This isn't working either. My end goal was to write a Python or Java code (since those are the two I am familiar with) to get me the result, but I guess if I can't get my manual requests working from Postman, getting it to work from code is a pipe dream.
You don't need the session tag, just change the param name in your postman request to appReceiptNum and it will work: https://egov.uscis.gov/casestatus/mycasestatus.do?appReceiptNum=LINXXXXXXXXXX
#Alok
What you require is term "headless browser / scraper"
just created a quick sample ( but in node.js)
const today = formatYmd(new Date())
const browser = await puppeteer.launch()
const page = await browser.newPage()
console.log("going to URL")
await page.goto(url)
await page.$eval('#receipt_number', (el,receipt) => el.value = `${receipt}`, process.env.RECEIPT_NUMBER)
await page.click('input[type="submit"]')
console.log("waiting for submission to be completed.")
await page.waitForSelector('div.current-status-sec').catch(t => console.log("Not able to load status screen"))
const status = removeTags(await page.$eval('.current-status-sec', el => el.innerText))
console.log(`${today}: ${status}`)
await page.screenshot({path: `./screenshot/${today}_screenshot.png`})
browser.close()
You can find the full repo here.
https://github.com/Parthashah/uscis-status-check
The code will provide back screenshot and status
I just created a simple USCIS web crawler scraper Spring Boot app using HtmlUnit.
The only thing is my crawler ignores the wrong case number. But is working. The github link is here: https://github.com/somych1/USCISCaseStatusWebScraper
public ResponseDTO getStatus(String caseId){
ResponseDTO responseDTO = new ResponseDTO();
//browser setup
WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getCookieManager().setCookiesEnabled(false);
webClient.getOptions().setTimeout(8000);
webClient.getOptions().setDownloadImages(false);
webClient.getOptions().setGeolocationEnabled(false);
webClient.getOptions().setAppletEnabled(false);
try{
// loading the HTML to a Document Object
HtmlPage page = webClient.getPage(url);
// case lookup
HtmlInput input = page.getHtmlElementById("receipt_number");
input.setValueAttribute(caseId);
HtmlInput button = page.getElementByName("initCaseSearch");
HtmlPage pageAfterClick = button.click();
// new page after click
HtmlHeading1 h1 = pageAfterClick.getFirstByXPath("//div/h1");
HtmlParagraph paragraph = pageAfterClick.getFirstByXPath("//div/p");
//setting response object
responseDTO.setCaseId(caseId);
responseDTO.setStatus(status);
responseDTO.setDescription(description);
} catch (IOException ex) {
ex.printStackTrace();
}
return responseDTO;
}
I wrote a container-bound script and now want to make a report from it, by inserting the code into a Google Docs file. The problem is that with copy & paste from the Script Editor, the code is no longer colored or indented. I will need your help because I don't know how to make it well done.
I have this code :
createAndSendDocument() {
// Create a new Google Doc named 'Hello, world!'
var doc = DocumentApp.create('Hello, world!');
// Access the body of the document, then add a paragraph.
doc.getBody().appendParagraph('This document was created by Google Apps Script.');
// Get the URL of the document.
var url = doc.getUrl(); // Get the email address of the active user - that's you.
var email = Session.getActiveUser().getEmail();
}
As tehhowch said you'll need to write your own javascript code to do syntax formatting and then use the output of that.
You can use this https://www.w3schools.com/howto/tryit.asp?filename=tryhow_syntax_highlight they already have the script in place you only need to encode your html and put inside div id="myDiv" and run the javascript code.
<div id="myDiv">
Your encoded html goes here
</div>
Example
<div id="myDiv">
<!DOCTYPE html><br>
<html><br>
<body><br>
<br>
<h1>Testing an HTML Syntax Highlighter</h2><br>
<p>Hello world!</p><br>
<a href="https://www.w3schools.com">Back to School</a><br>
<br>
</body><br>
</html>
</div>
Make sure you first encode your html. [< -> <, > -> >, etc]
Then you can use the output of that . Sample : https://docs.google.com/document/d/1h8oDOZ0ReTgwxnYt2JKflHWJdlianSWWuBgbWcSdJC0/edit?usp=sharing
Reference and further reads : https://www.w3schools.com/howto/tryit.asp?filename=tryhow_syntax_highlight
#app.route('/registerdriver', methods=['POST'])
def register_driver():
fname = request.form['fname']
lname = request.form['lname']
email = request.form['email']
mobno = request.form['mobno']
password = request.form['password']
file = request.files['driving_license']
file.filename = mobno+"_"+fname
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
Above is the code I used for saving the file. However the following error pops out while trying to save the file
flask.debughelpers.DebugFilesKeyError
flask.debughelpers.DebugFilesKeyError: You tried to access the file
"driving_license" in the request.files dictionary but it does not
exist. The mimetype for the request is
"application/x-www-form-urlencoded" instead of "multipart/form-data"
which means that no file contents were transmitted. To fix this error
you should provide enctype="multipart/form-data" in your form.
The browser instead transmitted some file names.
Can someone help me with this
In your html form tag include
<form action="/path" method="post" enctype="multipart/form-data">
</form>
This will send an email when a button gets pushed. However I am trying to call the FileResult, SaveDocument, to download a file right before redirecting back to the button page.
I am using a hardcoded file for now to download for the sake of testing. I can run the SaveDocument() result using a test button. I can't send an email, run the SaveDocument Action and then redirect.
[HttpGet]
public ActionResult send(int thisbatch, string listofpositives)
{
MailMessage mail = new MailMessage();
SmtpClient smtpServer = new SmtpClient("smtperServer");
smtpServer.Port = 25; // Gmail works on this port
smtpServer.EnableSsl = false;
mail.From = new MailAddress("xxxe#xxx.com");
mail.To.Add("xxxe#xxx.com");
mail.Subject = "Batch Closed";
mail.Body="some info stuff here";
smtpServer.Send(mail);
SaveDocument();
return RedirectToAction("AddColiform");
}
//THIS WORKS BY ITSELF CALLED FROM A BUTTON
public FileResult SaveDocument()
{
string filePath = Server.MapPath("~/XML_positives/Test1.xml");
string contentType = "text/xml";
return File(filePath, contentType, "Test1.xml");
}
Well, no solution was found (so far) to download a file and RedirectToAction back to the initial page in the same ActionResult. If someone can come up with a better answer I will take this one off.
So based on contents of string "listofpositives" I call a new View "Has Positives" with 2 buttons: One calls the FileResult Action and one redirects back to where everything started (this is desired).
A lot clunkier than just popping up a File Save As dialog and then moving on automatically. But I need to build something and move on. I feel sorry for my users. oh well.
Here is the code after I send an email and return to desired view:
if (listofpositives == "")
{
return RedirectToAction("AddColiform");
}
else
{
return RedirectToAction("HasPositives",new { thisbatch=thisbatch, listofpositives=listofpositives});
}
Here is the code for the whole extra view:
#{
ViewBag.Title ="HasPositives" ;
}
<h2>HasPositives</h2>
<p>Batch: #ViewData["batchid"] </p>
<p>Postives: #ViewData["listofpositives"]</p>
<br /><br />
Process your XML file using XMLSampling<br /><br /><br />
<button onclick="location.href='#Url.Action("SaveDocument", "Home")';return false;">Download Positive XML File</button>
<button onclick="location.href='#Url.Action("AddColiform", "Home")';return false;">Done</button>
I have a form that needs to submit a .csv file to the server and then append the words in it to a textarea in my page. I am using Remotipart to upload the .csv using AJAX but I cannot get the javascript in the server response to execute. Here are the relevant parts of my code:
The Form:
=form_tag(upload_canvas_words_admin_page_widget_widget_instance_path(widget.page, widget),:method=>'post',:remote=>true,:multipart=>true,:class=>"upload_words_csv") do
= label_tag "Upload File"
= file_field_tag "file"
= submit_tag "Upload"
The Controller:
def upload_canvas_words
#csv_text = params[:file].read
end
The .js.haml file:
= remotipart_response do
- if remotipart_submitted?
alert('#{#csv_text}');
alert('!');
- else
alert('WHYYYYY?');
When I look at the response I see the javascript being wrapped in a bunch of html, which I assume has something to do with the iFrame transport. But the javascript never actually executes.
Refer this issue. And try to follow the solution given here.
https://github.com/JangoSteve/remotipart/issues/89
So what happens is that reponse arrives to the browser with html entity (like ") inside the textarea. When the js code for evaluation is extracted the html entities are replaced by theirs respective characters (like " to ').
That's a characteristic of a textarea. So it doesn't get executed
Adding data: {type: :script} to the form should be the fix