How can we set html tags inside the mail content while sending mail using mailgun api? When I send it, the tags are displaying as it is.
But in smtp, we can set it as , isBodyHtml=true
Here is the quick code example that can help you to send email in HTML format.
RestClient client = new RestClient();
client.BaseUrl = new Uri("https://api.mailgun.net/v3");
RestRequest request = new RestRequest();
client.Authenticator = new HttpBasicAuthenticator("api", "key-XXX");
request.AddParameter("domain","yourdomain.com", ParameterType.UrlSegment);
request.Resource = "{domain}/messages";
//request.AddParameter("from", "Mailgun Sandbox <postmaster#sandboxc.mailgun.org>");
request.AddParameter("from", "from#mail.com");
request.AddParameter("to", to);
request.AddParameter("subject", subject);
request.AddParameter("text", "Text view of this email is not supported. Please view this email in HTML format. Thank you.");
//This will help you to send email in HTML format
request.AddParameter("html", body);
request.Method = Method.POST;
RestResponse stat = client.Execute(request) as RestResponse;
Hope this helps.
You can put your html content (with the tags) in the 'html' parameter when calling the Mailgun API.
Taken from Mailgun homepage (the last line is what you are asking for):
POST /messages
from = 'App <me#myapp.io>'
to = 'bob#gmail.com'
subject = 'Hello'
text = 'Welcome to our amazing app!'
html = '<p>Welcome to our amazing app!</p>'
Hope this helps
Related
I want to send email using Django. In the mail body , I want to send Bootstrap "Card" which contain "Image" and HTML content.
Sending mail is successful. But, It is not showing the image in the received mail. Also, It is not in the Bootstrap "Card" format.
Please some one help me.
views.py
emailSubject = "Mail from XYZ.COM"
emailOfSender = EMAIL_HOST_USER
emailOfRecipient = viewed_bog.profile.user.email
html_content = render_to_string('receipt_email.html', {'item': viewed_bog, }, request=request)
try:
emailMessage = EmailMultiAlternatives(subject=emailSubject, body=html_content,
from_email=emailOfSender,
to=[emailOfRecipient, ], reply_to=[emailOfSender, ])
emailMessage.attach_alternative(html_content, "text/html")
emailMessage.send(fail_silently=False)
except SMTPException as e:
print('There was an error sending an email: ', e)
receipt_email.html
This is the HTML template containing Bootstrap 4 "Card" using Django-templating language. With in the Card I am having Image.
Now, I am able to send mail successfully. But Image is not showing in the received mail. and also, mail body is not in the "Card" format.
I will assume that you are loading the css from a bootstrap.css file and as most mail providers block loading css and js files for security reasons you should use inline styling in the template that you want to send.
Eventually this an online tool that i use when i want to compile regular css to inline css.
css inline tool
I am a newcomer, not a professional coder (so be gentle), trying to build a Flutter app that must connect to a web/server API in HTTP.
According to the doc, to make a connection a header must be used, this header uses the Basic Ath method, with login and password + a content type.
Till that point I think I have found how to do (see code snippet hereunder) but I have to send a user id and a user password to the API in order to receive back user data. And I must humbly confess that I am stuck there...
I thank you in advance for your help!
Bernard
My code (after importing dart:convert et package:http/http.dart + installed the required dependencies) :
void brol() async {
String username = 'user';
String password = 'pass';
String userpass = '$username:$password';
String basicAuth =
'Basic ' + userpass;
print(basicAuth);
Response r = await get('https://www.adresse/login.php',
headers: {'authorization': basicAuth});
}
Many Thanks in advance for your answer,
Bernard
Your credentials should be in base64. You can visit the SO post in the comment.
Your code should be look like this:
main() async {
String username = 'user';
String password = 'pass';
String basicAuth =
'Basic ' + base64Encode(utf8.encode('$username:$password'));
print(basicAuth);
Response r = await get('https://www.adresse/login.php',
headers: <String, String>{'authorization': basicAuth});
print(r.statusCode);
print(r.body);
}
See also this blog post.
I am having trouble figuring out how to put an unsubscribe link in my email that is SMTP integrated with Mailgun.
Any thoughts?
Mailgun provides you with several unsubscribe variables:
1) %unsubscribe_url% -- link to unsubscribe recipient from all messages sent by given domain
2) %tag_unsubscribe_url% -- link to unsubscribe from all tags provided in the message
3) %mailing_list_unsubscribe_url% -- link to unsubscribe from future messages sent to a mailing list
If you include these variables in your emails, any recipient that clicks on the url will be automatically unsubscribed and those email addresses will be blocked from receiving future emails from that domain or message tag as appropriate.
reference https://documentation.mailgun.com/user_manual.html#tracking-unsubscribes
You can use it in a href link:
Click here to unsubscribe
Instead of giving entire domain as %unsubscribe_url% , it is better to add %tag_unsubscribe_url% only, so that all the tags which are part for the current email will get unscubscribe.
Here is the code
HTML link will be like
<a style="color: #8798AD;margin: 0;text-decoration: none;" href="%tag_unsubscribe_url%">Unsubscribe</a>
This will add unsubscribe link to all tags which are part of the current send email request.
so, it my send email request has 2 tags (i.e. Orage and Mango) this two tag will get unsubscribe by mailgun.
So if you send any email which contains one of these tag, then that email will not get deliver to client.
Java code example:
String from = "alpesh#jikadra.com";
String to = "alpesh#stack.com";
String subject="Sample email";
String replyTo="no-reply#jikadra.com";
String html = "<body><h1>Hello</h1><a style="color: #8798AD;margin: 0;text-decoration: none;" href="%tag_unsubscribe_url%">Unsubscribe</a></body>";
List<String> tags = new ArrayList<String>();
tags.add("Mango");
tags.add("Orange");
MailGunRequest mailGunRequest = new MailGunRequest(from, to, subject, html, tags, replyTo);
ResponseEntity<MailGunResponse> mailGunResponseResponseEntity = mailGunClient.sendEmail(mailGunRequest);
for more reference refere : https://documentation.mailgun.com/en/latest/user_manual.html#sending-via-api
I have started a server using Confluence on Centos and have created one page with a table.
Now I want to connect to my page then parse html there and find row&columns but I cannot connect to the page.
My page is located on: http://localhost:8090/display/TEST/Confluence
How can I connect to my page and parse the HTML?
You can use a confluenca api to get the page ID
from atlassian import Confluence
space = '~MYSPACE'
title_parent = 'PARENT_PAGE_ID'
p_id = confluence.get_page_id(space, title_parent)
print(p_id)
title = 'New page'
body = 'This is the body of a new page'
status = confluence.create_page(space, title, body, parent_id=p_id, type='page',
representation='storage')
print(status)
Take a look at Atlassian Example here. For updating your page, you need to know your page ID.
It is better to make two request. The first will be a search that will return you the ID of the page, while the latter will return for its contents.
Search
import requests
url = confluence_host + '/rest/api/content/'
res = requests.get(url=url + 'search',
params={'cql': 'space="TEST" AND title="Page Titile'})
page_id = res.json()['results'][0]['id']
Get HTML
import requests
url = confluence_host + '/rest/api/content/'
page = requests.get(url=url + page_id,
params={'expand': 'body.storage'}).json()
html = page['body']['storage']['value']
I am atempting to post a new url to a service on ESRI (I own it) with a post using Requests. After printing the line post_url the JSON is updated as I want it however when I post it nothing happens despite getting a 200 status. Is the issue with the post or the find / replace?
json_url = "https://www.arcgis.com/sharing/rest/content/items/serviceID?&token=XXX"
update_url = "https://www.arcgis.com/sharing/rest/content/users/USERNAME/folder/items/ServiceNumber/update?"
get_json = requests.get(json_url)
load_json = str(get_json.json())
find = "findme"
replace = "replace"
post_url = load_json.replace(replace, find)
a = requests.post(update_url, data={"url": post_url, "token": "XXXX", "f":"json"})
print a.status_code
The issue is with the post
I changed the post to this:
requests.request("POST", update_url, data={"url": post_url, "token": token, "f":"json"})
update_url needs to be the API update endpoint:
https://www.arcgis.com/sharing/rest/content/users/USERNAME/FOLDER/items/Endpoint /update?"
post_url needs to be: "whatever you want" in my case It was a search and replace variable of the the existing URL in the JSON and update, because of a server migration.