Click "Send" button of G-Mail programmatically - c#

I am creating an Email Sending Software. So far i am able to open chrome and fill the details of the email (subject,body,attachments and all) but i wanted to know is there any way i can click Send button of G-Mail programmatically too?
Code for filling details in chrome
Process ps = Process.Start("chrome.exe", "https://mail.google.com/mail/u/0/?view=cm&fs=1&tf=1&to=a#gmail.com&bcc=b#gmail.com);
Note I haven't used SmtpClient to send email because it was not fulfilling my customized requirement (sorry cannot disclose the reason).

The way you want this, is not possible. Process.Start opens a new Process. In this case it opens Google Chrome, with the URL you sent with it. This URL contains a querystring containing the subject and the body of the email. This is possible, because Google reads this on the server-side, and puts it in the right fields. There is no way to enter the send button though. This is a POST action, which can not be triggered by a URL.
C# form, does have a WebBrowser class. From here you can access buttons and click them, but I don't think Google will allow this, and most likely send you a captcha. (That is, if you manage to login in the first place.)

I can't help with the simulated button press you're looking for, but I can suggest that you rather try to use the Gmail API to do what you're trying to do:
https://developers.google.com/gmail/api/?hl=en
This would be a more reliable and stable way to send gmail programmatically, and you still don't have to use the smtp object directly.

You should probably use Selenium (WebDriver). It allows you to control browser from c# code, navigates pages, traversing DOM etc..

Related

Using .Net how can I programmatically navigate to a webpage, interact with it via code, then get particular values from a newly generated page

I have a scenario where I would like to automate programmatically the following process:
Currently, I have to manually
Navigate to a webpage
Enter some text (an email) in a certain field on the webpage
Press the 'Search' button, which generates a new page containing a Table with the results on it.
Manually scroll through the generated results table and extract 4 pieces of information.
Is there a way for me to do this from a Desktop WPF App using C# ?
I am aware there is a WebClient type that can download a string, presumably of the content of the webpage, but I don't see how that would help me.
My knowledge of web based stuff is pretty non-existent so I am quite lost how to go about this, or even if this is possible.
I think a web driver is what you're looking for, I would suggest using Selenium, you can navigate to sites and send input or clicks to specific elements in them.
Well, I'll write the algorithm for you but you also need to some homework.
UseWebClient get the htm page with the form you want to auto fill and submit
Us regex and extract the action attribute of the form you want to auto submit. That gets you the URL you want to submit your next request to.
Since you know the fields in that form, create a class corresponding to those fields, let's call the class AutoClass
Create a new instance of your auto class and assign values you want to auto fill
Using WebClient to send your new request with the url you extracted from the form previously, attach your object which you want to send to the server either through serialization or any method.
Send the request and wait for feedback, then further action
Either use a web driver like Puppeteer (Selenium is kinda dead) or use HTTPS protocol to make web requests (if you don't get stopped by bot checks). I feel like your looking for the latter method because there is no reason to use a web driver in this case when a lighter method like HTTP requests can be used.
You can use RestSharp or the built in libraries if you want. Here is a popular thread of the ways to send requests with the libraries built in to C#.
To figure out what you need to send you should use a tool like Fiddler or Chrome Dev Tools (specifically the Network tab) to see what you need to send to acheive your goal as you would in a browser.

MS Bot Framework - pass data through markdown link

Is it possible to pass data through a markdown link? So for example:
var html = "[link1](test1) [link2](test2)";
var reply = message.CreateReply();
reply.Text = $"Welcome {newMember.Name + html}!";
client.Conversations.ReplyToActivityAsync(reply);
Is there a way to pick up the click event that would let me know which link was clicked?
In bot framework, if you are trying to collect data off of link click (or button of the OpenUrl type). The recommended way is by using a 302 redirect. This is because you generally do not have access to anything from the front end as stuartd is pointing out. For example, if you have a facebook bot how would you capture what the user clicks since nothing is sent to the bot? This is the problem you are running into. You would essentially have to send an activity to the bot when the user clicks a link, but without access to the Facebook front end how do you send that on click?
If you would like to see an example of a 302 redirect in a bot, I have made this example which has both Node and C# versions. This project shows how to do this with a button using the OpenUrl action type but can be applied to a link as well.

How to open a new window without refresh?

I have this code implemented in my application, but whenever i click onto the link, it do help me open a new window. But the original page was "refresh", it kept go all the way back to the top. How can i resolve this problem?
code:
Response.Write("<script>window.open('" + url + "')</script>");
As I understand it, each time you click the link the page is being send to the server where the event is handled (with some C#). If you do that, the server will send the whole page back.
You probably want to control this on client side, with some Javascript.
That said, what you are problably looking for is the attribute target of the link:
something
That will tell the browser that you want to open another tab or windows when the user click the link, and then there request the page specified by url in that tab or window.
Sounds like you want Response.Redirect(myURL)
When you click on the link and handle it in the code behind, that means the link is run at the server side, so it has to post back, which makes it look like it's "refreshing", but it's actually posting back.
You need to handle the opening of the new window on the client's side via Javascript.
If your're writing this to your page, this will redirect you to the url you want
Response.Write("<script>;location.href='" + url + "'</script>");

How do I use the mailTo protocol on in C# for a sharepoint web part?

I've been trying to use the mail to protocol in my C# code - but its not working for me as everytime I press the button that is supposed to run the mailto code - the page refreshes instead and the outlook new message window does not open
My code is the following
System.Diagnostics.Process.Start("mailto:"+email);
"email" above is a string object that is retrieved from a sharepoint list.
Given your "mailto:"+email code fragment I am assuming that what you really want is this:
You want the user on your website to press a button which opens a new Outlook message with your E-Mail address, correct?
No need to use server side C# for this, as this is regular HTML and the default e-mail client is handling the mailto: protocol (just like your browser handles the http: protocol).
All you need to do is to have something like this:
Mail me on your site and once the user clicks this link the default mail program (might not be outlook) will handle the mailto link. You could also do this via a button.

How do I use the Windows Mail Protocols? (C#?)

Well, for my program(s) I'd like to let the user send me an e-mail with any errors. Instead of relying on a forsaken SMTP server, I decided to let the user use his very own e-mail client to send an e-mail to a specified address.
So what I need is:
A sender (should not be changeable) (example: mysupportemail#gmail.com)
An attached file (should not be changeable) (example: "C:\a file.log")
(Optional) A body (changeable)
I hope it is possible!
You can use the mailto command for this. See http://msdn.microsoft.com/en-us/library/aa767737(VS.85).aspx for more information. Some mail clients support attachments on this. See the comments of the MSDN page for some information on this.
The mailto protocol has limitations, such as not being able to specify an attachment (some mail clients support it, but it's not in the official protocol). Your best option is probably to use the MAPISendMail function to let MAPI do the hard work. See this article for details:
Sending files via the default e-mail client
I used this technique in the past, it seems to work perfectly.
Using mailto directly from you application cause potential problems. If you have specified mail account for receive e-mails you can be sure, that someone will use it somehow to sent you spam or thousands unwanted emails. In our company we struggled with this problem many times - at last, we decided to allow our customers to report problems in any other way - web page form.
Now, when customer click 'report problem' this option displays a form for reporting bugs in default web browser. Opened link include some additional information which causing partial fill of the form opened by customer. Now, we have an intermediate layer and absolute control on server side who report problem (ip) and we can limit reporting for specified users. Next advantage of these solution is that you can forward emails to different departments depending on what form fields are marked/filled with.
Well, I have found the perfect solution!
For those who want to see it...
http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/a75533eb-131b-4ff3-a3b2-b6df87c25cc8
http://www.eggheadcafe.com/community/aspnet/2/10019665/email-through-gmail-in-c.aspx

Categories

Resources