I'm trying to send email using JNDI, but for some strange reason the from field is not set.
context.xml:
<Resource name="email/user"
description="support email"
auth="Container"
type="javax.mail.Session"
username="user#server.net"
password="pass"
mail.debug="false"
mail.user="user#server.net"
mail.from="user#server.net"
mail.transport.protocol="smtp"
mail.host="mail.server.net"
mail.smtp.host="mail.server.net"
mail.smtp.auth="true"
mail.smtp.from="user#server.net"
mail.smtp.starttls.enable="true"
mail.smtp.submitter="user#server.net"/>
And how I'm getting this to application:
Context ctx = new InitialContext();
Session userEmail = (Session) ctx.lookup("java:comp/env/email/user");
And everything is fine, but when I'm sending this email to some servers I receive return message:
We can't accept your message - missing From: (#5.3.0)
Additional question:
How to set nice looking from?
I tried this:
mail.from="company XYZ <user#server.net>"
But it doesn't work....
I found the reason. The issue was in the message creation.
I was missing the messsage.setFrom();
Code:
Message message = new MimeMessage(mailSession);
message.setFrom(); //this was missing
message.setSubject(subject);
message.setContent(content, "text/html; charset=" + charset);
//... set recipients, ....
Transport.send(message);
Now my both questions are answered. The "nice looking from" is also working now.
Related
Function to send emailable-report.html via email is not working when run from Jenkins but it works fine in local.
I have a function just to send email with emailable-report.html after test case execution. It is works fine in my local machine. However when run from Jenkins, build success but no email is sent. I already set hostname and smtp port is matched with Jenkins server.
String reportLocation ="..\\target\\surefire-reports\\emailable-report.html";
EmailAttachment attachment = new EmailAttachment();
attachment.setPath(reportLocation);
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("Test Report " + timeStamp + ".html");
// Create the email message
MultiPartEmail email = new MultiPartEmail();
email.setHostName("x.x.x.x"); //SERVER .
email.setSmtpPort(25);
email.addTo("user#gmail.com");
email.setFrom("//another email address", "Me");
email.setSubject("Selenium WebDriver Test Report, run from Jenkin (SERVER) " + dateTest);
email.setMsg("-- This is a Test Report email. Please refer to the attachment for more details!");
email.attach(attachment);
// send the email
email.send();
System.out.println("Test Report Mail Sent Successfully");
Try "Extended E-mail Notification" in jenkins instead of custom functions.
Hi#Chau looks like you are passing the path in email body.Instead refer my screenshot where i have mentioned the path separately under Attahments in "Editable Email Notification"
I am trying to test an error handling route. The NotificationBuilder does not work as expected (it always returns false).
Created a main route and a test route to test the main route. I used Spring Boot - all other tests work fine, so there is no problem with the setup I guess.
errorHandler(deadLetterChannel("seda:errorQueue").maximumRedeliveries(5).redeliveryDelay(1000));
from("file://{{inputFolder}}?delay=10s&noop=true")
.routeId("InputFolderToTestSedaRoute")
.setHeader("myHeader", constant("MY_HEADER_CONSTANT_VALUE"))
.to("seda://testSeda")
.log(LoggingLevel.DEBUG, "**** Input File Pushed To Output Folder *****");
There is an error route too.
from("seda:errorQueue")
.routeId("ErrorHandlingRoute")
.log("***** error body: ${body} *****")
.log("***** Exception Caught: ${exception} *****");
I then used adviceWith() to throw an Exception in the main route.
Then created the NotifyBuilder.
NotifyBuilder errorRouteNotifier = new NotifyBuilder(camelContext)
// .wereSentTo("seda:errorQueue")
.fromRoute("ErrorHandlingRoute*")
.whenReceived(1)
.create();
Then I sent message using ProducerTemplate. But when I test the match condition, it always fails.
boolean done = errorRouteNotifier.matches(5, TimeUnit.SECONDS);
assertTrue("Should have thrown Exception and caught at errorQueue", done);
But the message is routed to the ErrorHandlingRoute as I can see the messages (body and exception) I asked to print there.
Please let me know what is the issue here. Thanks in advance.
I am using the GMail API to retrieve messages. The messages are machine generated, so follow a similar format.
Although most of the messages are fine, I am getting a DOMException using atob to decode the message body for a subset of the messages.
I think I've narrowed it down to messages that have a section in it that looks like:
--------------------- Sudo (secure-log) Begin ------------------------
jeremy => root
--------------
/usr/bin/docker - 5 Time(s).
---------------------- Sudo (secure-log) End -------------------------
Specifically I think that the problem happens because of the =>.
The error is:
Error parsing DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
Code fragment:
gapi.client.gmail.users.threads.get({
userId: 'me',
id: thread.id
})
.then(function(response){
var
content,
message = response.result.messages[0],
rawContent = message.payload.body.data;
try{
content = atob(rawContent);
}
This thread helped me Decode URL Safe Base64 in JavaScript (browser side)
rawContent = rawContent.replace(/_/g, '/').replace(/-/g, '+');
Fixed it up.
Ok.
I'm writing a POC (Proof of Concept) Logic App.
The logic app has a Service Bus connector wired to a queue.
I'm using peek/complete/abandon.
I wrote a client app (dotnet c# console app) that writes messages to the queue (nothing really to do with the logic app part).
I'm setting the Content Type to "text/plain".
string payLoad = #"{ ""myid"": ""1000"", ""mymessage"": ""1000 is great"" , ""myboolean"" : ""true"" }";
QueueClient queueClient = /* not seen here */;
brokeredMsg = new BrokeredMessage(payLoad) { ContentType = System.Net.Mime.MediaTypeNames.Text.Plain };
queueClient.Send(brokeredMsg);
Now I use Service Bus Explorer (4.0.104), and I see the message in the queue
The issue is that when my Logic App runs, its not seeing plain-text/json.
You can see it picked up the content-type.
But it garbly gooks the content itself.
Is there a way to get raw-text with this trigger?
Note, the documentation says:
let's look at the two Content-Types that don't require conversion or
casting that you can use in a logic app: application/json and
text/plain.
from :
https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-content-type
https://learn.microsoft.com/en-us/azure/connectors/connectors-create-api-servicebus
My C# console app packages.config (nothing to do with Logic Apps, but including for completeness)
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.1.0" targetFramework="net45" />
<package id="WindowsAzure.ServiceBus" version="2.1.4.0" targetFramework="net45" />
</packages>
APPEND:
I needed to do two thing to get it to work
One:
I had to change the "sender" code slightly.
QueueClient queueClient = /* not seen here */;
string ct = System.Net.Mime.MediaTypeNames.Text.Plain;
/* see https://social.msdn.microsoft.com/Forums/en-US/8fbf2391-8440-46db-bb47-648daccf46fd/servicebus-output-json-is-being-wrapped-in-a-xml-header-in-logic-app?forum=azurelogicapps and https://abhishekrlal.com/2012/03/30/formatting-the-content-for-service-bus-messages/ */
string payLoad = #"{ ""myid"": ""1000"", ""mymessage"": ""1000 is great"" , ""myboolean"" : ""true"" }";
brokeredMsg = new BrokeredMessage(new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(Convert.ToString(payLoad))), true) { ContentType = ct };
queueClient.Send(brokeredMsg);
And I used the hint Derek Li gave me.
I've accepted his answer as the-answer, but PLEASE NOTE I had to do slightly more than he suggested. The code above has the urls for the reason I changed the sender code.
In a nutshell, the constructor for BrokeredMessage that I was using was choosing a specific serializer for me.
BrokeredMessage(Object)
Initializes a new instance of the BrokeredMessage class from a given object by
using DataContractSerializer with a binary XmlDictionaryWriter.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.servicebus.messaging.brokeredmessage.-ctor?view=azureservicebus-4.1.1#Microsoft_ServiceBus_Messaging_BrokeredMessage__ctor
and after I figured out the answer, I found this SOF answer:
Azure Service Bus Serialization Type
You can use expression #base64ToString(triggerBody()?['ContentData'])" to convert it to string.
I'm working in getting a connection to cloudant done.
The following is using sag library for php:
<?php
header('Content-Type: text/html; charset=utf-8');
require_once('../../src/Sag.php');
//this credentials are from API key
$uName="";
$pName="";
$sag = new Sag('user.cloudant.com');
$sag->login($uName, $pName);
$sag->setDatabase('test');
try {
$result = $sag->get('/test/_design/wordsP/_view/errores');
echo ($result);
}
catch(Exception $e) {
error_log("Something's wrong");
var_dump($e);
}
?>
However I'm not getting expected result (). The view does work, if used just in the url bar.
The response is:
object(SagException)#3(6){
[
"message:protected"
]=>string(50)"Sag Error: cURL error #7: couldn't connect to host"[
"string:private"
]=>string(0)""[
"code:protected"
]=>int(0)[
"file:protected"
]=>string(73)"/home2/.../public_html/clant/src/httpAdapters/SagCURLHTTPAdapter.php"[
"line:protected"
]=>int(134)[
"trace:private"
]=>array(3){ .............
Is there something I'm not using corretly in the php script? (removed current password + username as well as account, but they're there).
Curl error 7 means you are unable to connect to the host or proxy:
CURLE_COULDNT_CONNECT (7)
Failed to connect() to host or proxy.
Source: http://curl.haxx.se/libcurl/c/libcurl-errors.html
When you connect to the URL from your browser if your browser is using a proxy, you will also need to configure sag to use that proxy.
Also, when you say that you replaced the account in your code example, did you mean that you replaced user in $sag = new Sag('user.cloudant.com'); with your actual username? If not, you will need to use your actual username.