I am trying to send the email using exchange web service c#. It works fine if body contains normal text. But the body contains the URL like below is not working. it is sending the mail, but URL is not coming in the receipt end.
url contains < >
http://localhost:52122/Home?Function=ABC&Parameter1=12345
Please help.
Thanks in advance
replace the body content with this code
string Url = "localhost:52122/Home?Function=ABC&Parameter1=12345";
string EmailBody = #"Email Body </br> please " + String.Format("<a href='{0}'>Click here</a>", Url);
Related
I am curently integrating the api to my application. One of the parameter is content_url which is a valid HTML URL for content. How to I pass whole url with query string?
API Endpoint parameter is located below.
var contentUrl
= "https://www.finnet.com.tr/CMS/OSMANLIMENKULTEST/MailSablon/RaporPaylasimHtml/OSMANLIKP/FXBULTEN/2020-01-20/null";
var url = "https://campaigns.zoho.com/api/v1.1/createCampaign?" +
"resfmt=json&" +
"campaignname=Campaign12&" +
"from_email=mert.metin#finnet.gen.tr&" +
"subject=Test Create Campaign 11&" +
"list_details=%7Bd6ef220cc42b50d7ddf3236cbb9b8847894375f7a7d2d66f%3A%5B%5D%2Cd6ef220cc42b50d71438a8b019c635e5894375f7a7d2d66f%3A%5B%5D%7D&" +
"content_url=" + contentUrl;
Content url is https://www.finnet.com.tr/CMS/OSMANLIMENKULTEST/MailSablon/RaporPaylasimHtml?SiteKod=OSMANLIKP&Kod=FXBULTEN&Tarih=2020-01-20
But I post url value, API gets the url until first & ampersand character. So remain parameter was missing. I need to pass whole url as a parameter.
Expected Result=https://www.finnet.com.tr/CMS/OSMANLIMENKULTEST/MailSablon/RaporPaylasimHtml?SiteKod=OSMANLIKP&Kod=FXBULTEN&Tarih=2020-01-20
Actual Result=https://www.finnet.com.tr/CMS/OSMANLIMENKULTEST/MailSablon/RaporPaylasimHtml?SiteKod=OSMANLIKP
My application is based on MVC and C# language. I also enclosed the url with double quotes but it is not work because of Api Response which is INVALID IMPORT URL.
You must encode the URL before passing as a parameter as
myURL="myURL1?redir=" + Server.URLEncode("myURL2?id=4&user=test");
It will create a correct URL without '?' and "&" characters as
myURL= myURL1?redir=myURL2%3id%34%26user%3dtest
To extract your redirect url from this encoded url you must use
HttpServerUtility.UrlDecode to turn it into a correct url again.
This question is for testing:-
There is a email website https://www.sharklasers.com where we can create temporary emails. I'm using this site to send email and get some verification code. As of now i'm using selenium which takes some time.
So, I decided to use RestSharp(C#) to read the email.
General Steps:
Step 1: Navigate to https://www.sharklasers.com
Step 2: Edit and set an email id (creates email id with just one click)
Step 3: Sending email to the newly created temp email(from some mail like gmail..)
Step 4: Click on the received email.(Here will get the unique URL for the email)
That's the steps.
This I tried with POSTMAN which is working properly.
POSTMAN Steps: (Captured the traffic using charles proxy)
1.Create Email - POST Request :
https://www.sharklasers.com/ajax.php?f=set_email_user&email_user=Emailidhere&lang=en&site=sharklasers.com&in=+Set+cancel
2.Get list of emails - GET Request : https://www.sharklasers.com/ajax.php?f=get_email_list&offset=0&site=sharklasers.com&in=Emailidhere&_=1547991487
I'm having issue with the 2nd step.
Below observations may help you to help me.
Observation in browser:
- Entering the 2nd URL directly to the browser - getting some default information about the sharklasers website.
- First navigate to the sharklasers website , set the email which is created , then in new tab , enter the 2nd URL - getting the expected response.
Observation in POSTMAN:
- Entering the 2nd URL directly to the POSTMAN - getting some default information about the sharklasers website.
- First sending the set the email Request JSON file here, then sending Request to the 2nd URL JSON file here, getting the expected response.
Observation in Visual Studio (RestSharp C#)
- Entering the 2nd URL directly to the POSTMAN - getting some default information about the sharklasers website.
- First sending the set the email Request , then sending Request to the 2nd URL - getting the same default information about the sharklasers website. NOT Getting the expected response
Set Email RestSharp code taken from POSTMAN:
var client = new RestClient("https://www.sharklasers.com/ajax.php?f=set_email_user&email_user=testemailstackoverflow&lang=en&site=sharklasers.com&in=+Set+cancel");
var request = new RestRequest(Method.POST);
request.AddHeader("Postman-Token", "ddae1b83-b974-4e9b-a013-940c2e91d50a");
request.AddHeader("cache-control", "no-cache");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
Get Email RestSharp taken from POSTMAN:
var client = new RestClient("https://www.sharklasers.com/ajax.php?f=get_email_list&offset=0&site=sharklasers.com&in=testemailstackoverflow&_=1547991487");
var request = new RestRequest(Method.GET);
request.AddHeader("Postman-Token", "7625df90-9ee9-46e6-b9ca-568dde93618e");
request.AddHeader("cache-control", "no-cache");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
Now i want to get the same response in Visual studio(Restsharp C#) which is observed in POSTMAN and browser.
This question may be little confusing. If any questions regarding the question , please ask me.
Thanks in advance.
I am trying to send an sms from my website.
Below is the HTTP api which works perfectly.It sends the msg and returns the string
http://sms.mywebsite.com/api/sendmsg.php?user=MYID&pass=MYPASS&sender=SENDERID&phone=1234567980&text=Test Message&priority=ndnd&stype=normal
But i want to use it in C#.Accept mobile number from TextBox1 and Message from TextBox2
WebRequest webRequest = WebRequest.Create("http://sms.mywebsite.com/api/sendmsg.php?user=MYID&pass=MYPASS&sender=SENDERID&phone=" + TextBox1.Text + "&text=" + TextBox2.Text+ "&priority=ndnd&stype=normal")
The first statement is executing if i paste the http code directly in the website and i recieve the smsin my mobile .But the WebRequest statement dosent send the sms
TextBox1.Text=123456789;//some mobile number
TextBox2.Text="Thankyou for registering # MyWEBSITE. A verification email has been sent to Your email";
You seem to be only creating a web request object and not executing it.
var response = webRequest.GetResponse();
Refer to the documentation # https://msdn.microsoft.com/en-us/library/bw00b1dc(v=vs.110).aspx
I would also recommend you use a HttpClient instead.
You should use Server.UrlEncode. Probably, you have some spaces and special characters in the text message.
WebRequest webRequest = WebRequest.Create(Server.UrlEncode("http://sms.mywebsite.com/api/sendmsg.php?user=MYID&pass=MYPASS&sender=SENDERID&phone=" + TextBox1.Text + "&text=" + TextBox2.Text+ "&priority=ndnd&stype=normal"))
I have an ASP.NET MVC web site. One of my routes is a URL that takes 5 parameters. For the sake of illustration, these parameters are named parameter1, parameter2, parameter3, parameter4, and parameter5. Currently, I'm constructing a URL in some C# code that will POST to the mvc action via a WebClient. that code looks like this:
WebClient myWebClient = new WebClient();
myWebClient.UploadStringCompleted += myWebClient_UploadStringCompleted;
string url = "http://www.example.com/customer/" + parameter1 + "/orders/" + parameter2 + "/" + parameter3 + "/" + parameter4 + "/" + parameter5;
myWebClient.UploadStringAsync(new Uri(url, UriKind.Absolute));
I'm confident that the UploadString method does a POST. I need to do a POST, because my parameter values can be very long. In fact, I estimate that occasionally, the total url length may be 20000 characters long. Regardless, I get a 400 error when I attempt to post my data. In an effort to debug this, I'm trying to figure out how to simulate a POST in Fiddler.
Assuming that I am passing values via a query string as shown above, what values do I enter into Fiddler? From the Composer tab, I'm not sure what to enter for the Request Headers area. I'm also not entirely sure what to enter for the url. I'm not sure if I put the entire URL in there, including the parameter values, or if those belong in the Request Headers.
What I need to enter into Fiddler, so that I can debug my issue?
Basically all your parameters are a part of the URL, and this is the root of your problem. Here is what is going on: you are hitting the URL length limitation, and receiving a "400 Bad request" error. In real world most web browsers do not work with URLs more than 2000 characters long.
To resolve this problem I would suggest doing a bit of refactoring, so that request is posted to the URL http://www.example.com/customer/parameter1/orders or even http://www.example.com/customer/orders with parameters send in request body. Here is how test such request in Fiddler:
On Composer tab choose POST request verb
Specify the URL as
http://www.example.com/customer/parameter1/orders
or
http://www.example.com/customer/orders
In Request Headers section you can set content type header like
Content-Type: application/x-www-form-urlencoded
or any other header you might require. Or just leave it blank which will work in your case.
Finally in Request Body field list your parameters in query string form
parameter1name=parameter1value¶meter2name=parameter2value
In this new case here is how you can send such a request using WebClient:
WebClient myWebClient = new WebClient();
myWebClient.UploadStringCompleted += myWebClient_UploadStringCompleted;
string url = "http://www.example.com/customer/orders";
string data = "parameter1name=parameter1value¶meter2name=parameter2value";
myWebClient.UploadStringAsync(new Uri(url, UriKind.Absolute), data);
I simply mimic the exact request that was sent.
This is how I do it:
Open Fiddler
Go to the page that I want to re-issue the command i.e. repeat the bug step but watch for the request in the list
Select it from the list and right-click, go to replay > reissue and edit
This build a replicated request but hits a break point before it is sent (You will see the red bar on the right)
Above this you can edit the values that were sent by double-clicking on any of them in Headers, QueryString etc
Then hit Run to Complete
I am trying to send a simple HTTP request like this:
var client = new WebClient();
string myString="this is the string i want to send";
message = client.DownloadString("http://www.viralheat.com/api/sentiment/review.xml?text=" + myString + "&api_key="+currentKey);
but some of the strings I send includes # or & or such characters, so I want to encode the string first before sending it, because it throws an error if it includes these special characters without being encoded.
Call Uri.EscapeDataString.
Unlike HttpUtility, this works on the client profile too.
Use HttpUtility.UrlEncode