I am creating an email using the c# MailMessage and I am trying to add a checkbox that doesn't need to be clicked. The checkboxes will be used for a checklist of what to bring to an event (like a packing list). I have:
MailMessage objEmail = new MailMessage();
objEmail.From = new MailAddress("sender#hotmail.com");
objEmail.To.Add(new MailAddress("example1#hotmail.com"));
objEmail.CC.Add(new MailAddress("example2#hotmail.com"));
objEmail.Bcc.Add(new MailAddress("example3#hotmail.com"));
objEmail.Subject = "Packing list!";
objEmail.IsBodyHtml = true;
objEmail.Body = #"<div width=""800px"">
<h3>WHAT TO BRING</h3>
<form>
<input type=""checkbox"" name=""item"" value=""shirt"">Shirt<br>
<input type=""checkbox"" name=""item"" value=""shoes"">Shoes
</form></div>";
but when I send the email the checkboxes do not appear in the list.
Output in outlook using outlook.com:
WHAT TO BRING
I have a bike
I have a car
Output in outlook using Microsoft Outlook:
WHAT TO BRING
[ ]I have a bike
[ ]I have a car
Output in outlook using hotmail.com:
WHAT TO BRING
I have a bike
[]I have a car
So the problem is with the mail client but it is inconsistent what the problem is. I s there any way to make a consistent output?
Is there a way with html that works to create the checkboxes or do I just need to include images of a checkbox?
Thanks in advance.
My guess is that their in inconsistency with the way the email clients handle check boxes.
Why not change each to [X] which is plain text so all email clients can see it.
Outlook.com has an issue to display multiple check or radio buttons within a single parent. / / / etc
add a table in there and add the 2 check boxes in a separate row and it should work fine.
weird Microsoft thinking
All email clients have their own rules on what's allowed. You may find that most providers don't allow JavaScript and just some allow positioning elements while some don't.
Your best bet is to use a plain text form or maybe an image of what the form looks like. And when I say image, don't mean make the entire thing an image, have images for each checkbox. Once you click anywhere in this form it opens up on your site to interact with it.
Furthermore, you really shouldn't be building html in your code like you are. Put that in an MVC view or a webforms partial and invoke the file from code. Using this approach you can still inject dynamic data into the template while putting the HTML where it belongs.
Related
I am working with Outlook addin which is perform task for creating new mail item and sent to users.
Now what I want is, I don't want to allow user to add email in To field, in short I need To field to remain disable for user, but I am not getting any way to disable it.
MailApp.Application oApp = new MailApp.Application();
oMailItem =(MailApp.MailItem)oApp.CreateItem(MailApp.OlItemType.olMailItem);
oMailItem.To = "abc#gg.com"; // need to disable this for end user.
oMailItem.Subject = "Xyz";
oMailItem.HTMLBody = "Xyz";
oMailItem.Display(false);
oMailItem.Actions[1].Enabled = false; // it allow index from 1 to 4 which disable reply , reply all, reply to and forward option on current mail but not To field.
Please help to achieve this in my addin. How can I disable To field for end user?
The only way to disable the To field address control is to customize the form design, remove the controls and publish that form definition to that user's Personal Forms library. For more information, see https://learn.microsoft.com/en-ca/office/vba/outlook/concepts/forms/customizing-form-pages-and-form-regions.
In addition to Eric's suggestion, you can try to hook the MailIem.PropertyChange event, and when (and if!) the "To" property is modified, reset it back.
There is no need to customize the built-in Outlook form and then re-publish it. It is a very old technology which is not used any longer by add-in developers.
You can use Outlook form regions and place the form to the Replace-all layout which replaces the whole Outlook form with the form region. Read more about that in the Create Outlook form regions article on MSDN.
Also, you may consider using Add-in Express. They provide the CompleteReplacement layout which also completely replace all pages of any Inspector window.
Note, in both cases, you can use any .net controls for creating a custom UI in Outlook
What I am trying to achieve is this:
I am sending an email to someone within my organization asking them to attend a meeting (this will all be on the same domain, i.e. #gmail.com), From here, I want them to be able to click a button or label, which will send an email to a specific person (so basically a confirmation email that they accept the meeting). I am sending the 1st email in C# by using the following code:
string theBody = "Do You Accept: " + "Click Here/Button"
Message objMessage = new Message();
objMessage.NameFrom = Convert.ToString(ConfigurationManager.AppSettings["SMTPSendingName"]);
objMessage.EmailFrom = Convert.ToString(ConfigurationManager.AppSettings["SMTPSendingEmailAddress"]);
objMessage.NameTo = "Subject";
objMessage.EmailTo = "To#email.com";
objMessage.EmailMessage =
string.Format(theBody);
Where I have written "Click Here/Button" is where I would like the clickable text or button, that sends an email back to a hard coded email address, something like the following:
string returnEmail = "mailto:return#mail.com?subject=Accepted?body=" + theBody;
To Clarify:
An email is sent to person a from C# using the above code block 1
When person a receives the email, I want them to be able to click a button or clickable text, that in turn sends an email to a person b
This clickable button or text must be embeded in C#
My Organisation are using Outlook 2016
This is they way I though would be best, however I am open to any better suggestions into how I can achieve something like this. Thankyou in advance for your help.
Below is an example image of what I have, as you can see its just a long hyperlink, which does work for now. This opens up a new outlook message, and the user has to press send. I would prefer this to happen all in one click but if this is not possible, then that is ok.
You could have an endpoint in your api, that will be hit when the user clicks on accept. On that endpoint, you could use Office365 APIs (https://msdn.microsoft.com/en-us/library/office/dn776319(v=exchg.150).aspx), more specifically, the Calendar API, to accept the meeting.
You can't. HTML in Outlook is rendered by Word, and it will not run any scripts. The best you can is provide a link that will be opened in the user's browser, which can then do something meaningful.
have you considered a custom outlook form?
https://msdn.microsoft.com/en-us/library/office/ff868929.aspx
If you're not on an exchange backend, you might have to send the form template around to your users. Exchange allows for "Organizational Forms" which all users can get.
The custom form allows you to add buttons and code-behind in the custom form for very much what you are asking.
I am working on a project which is Analysis of Papers from Google Scholar. What I do is basically, parsing the HTML, storing related fields into database etc. However, I am stuck at a point, while I am taking the Titles of the publications, I realized, I am able to get first twenty elements. But, there are sixty papers in related account:
http://scholar.google.com/citations?user=B7vSqZsAAAAJ
So, I think as a solution, I need to click to the 'show more' button programmatically, so I can have all the Title's, Publication Venue etc.
What do you think? How can I perform that kind of action?
Edit: I checked the 'show more' button, while there is nothing to show as a next page, its html code still remains same. As a solution I can use loop for n times. However, I am looking for more robust solution.
Thank you for your time!
If it is clicking on a button within a WebBrowser control on a Windows Form Application, then 'Yes' you can do it.
There are ways of getting more control over identification by using XPath.
(You might need to use Javascript to use XPath for object interactions - since you haven't asked for that, I will assume you don't need it)
webBrowser.Navigate("http://www.google.com");
// Or
HtmlElement textElement = webBrowser.Document.All.GetElementsByName("q")[0];
textElement.SetAttribute("value", "your text to search");
HtmlElement btnElement = webBrowser.Document.All.GetElementsByName("btnG")[0];
btnElement.InvokeMember("click");
Or even typing into text boxes with
webBrowser1.Document.GetElementById("gs_tti0").InnerText = "hello world";
If its this website specifically, there is a simple workaround. Change the query string to what records you want.
http://scholar.google.com/citations?user=B7vSqZsAAAAJ&cstart=0&pagesize=2000
I have a webpage with 2 search fields (top and bottom) and some text in-between them and I want to send a query to the bottom field. Both fields are identical (same code).
I tried storing the bottom one in a variable and use that variable to send the keys, but somehow it always sends the text to the first one.
var bottomSearch = _WebDriver.FindElements(By.Id("inputBox"))[1];
Assert.IsTrue(bottomSearch.Displayed);
bottomSearch.Clear();
bottomSearch.Click();
bottomSearch.SendKeys("test");
bottomSearch.SendKeys(Keys.Enter);
So: Clear() works and properly deletes any text already present in the bottom search, Click() also works, SendKeys sends text to the top searchbox and SendKeys(Keys.Enter) goes back to the bottom one and presses Enter from there.
I use the firefox driver and also tried selecting the element by CssSelectors or other identifiers but did not work.
Any help or ideas are most appreciated!
Thank you!
Here is the code for the search fields:
<div class="searchbox-input">
<input id="inputBox" class="querybox" type="text" placeholder="Entrer le terme recherché" name="inputBox" value="test">
</div>
OK, so after 2 days of trial and error I asked the website's devs to change the id of the bottomSearch and now everything works well.
After all these tries I'm tempted to suspect a bug in the driver or the SendKeys() method, but since I failed to found any reference to back this up and I successfully dealt with same ID fields before, maybe it's just something in the website's implementation or mine.
So in conclusion, follow the best practice advices and this should never happen :)
I'm just using watin to fill some textfields but sometimes it writes in the wrong textfield because the textfields name is not clear here's my code
IE browser = new IE(site);
browser.TextField(Find.By("type","text")).TypeTextQuickly(username.ToString());
browser.TextField(Find.By("type", //"password")).TypeTextQuickly(pass.ToString());
browser.Button(Find.By("type", "submit")).Click();
Edit your HTML code and setup ID´s for your input elements. Then use Find.ById
One option could be to see if there is an outer element (such as a Div) you can find first, and afterwards get the text fields from that element instead of from the browser variable. That could for instance look like this:
Div div = browser.Div(Find.ById("divId"));
//Div div = browser.Div(Find.ByClass("divClass")); // or like this for instance...
TextField text = div.TextField(Find.By("type", "text"));
TextField password = div.TextField(Find.By("type", "password"));
Button submit = div.Button(Find.By("type", "submit"));
I am unclear as to your knowledge of WatiN and testing so I will start from the begginging. First you need to go on the webpage you want to test and (in IE) go to tools -> Developer tools. Click the white arrow in the menu then proceed to click the box you wish to utilize. Once you do this the developer tools will give you the code for the textbox including many ways you can reference it in your code. For example, using dev tools in IE I can automate logging into my gmail like this:
IE browser = new IE("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=http://mail.google.com/mail/&scc=1<mpl=default<mplcache=2");
browser.TextField(Find.ByID("Email")).TypeText("myemail#email.com");
browser.TextField(Find.ByID("Passwd")).TypeText("mypassword");
browser.Button(Find.ByID("signIn")).Click();
There are many Find.By commands so there is no reason you can't acess ANY textfield you wish. You just need the html and to be specific to which one you want to write into. I hope this helps :)