BlackBerry Looking up email address - email

I am working on a BlackBerry Application that is going to lookup the email address registered to the device. I am using this code to accomplish:
Session session = Session.getDefaultInstance();
System.out.println("############### got session ################");
if (session != null) {
Store store = session.getStore();
System.out.println("################ got store ######################");
ServiceConfiguration serviceConfig = store.getServiceConfiguration();
System.out.println("################ got config #####################");
email = serviceConfig.getEmailAddress();
}
This works perfectly for devices that have already registered an email address. But if the device doesn't have an address registered to it this line:
email = serviceConfig.getEmailAddress();
Never returns. So my entire application stalls out indefinitely. What is the best approach for solving this? My first idea is set a timer task that will set the email String to some default value such as "No Address Registered" after 1 or 2 seconds. Is there some better way to get notified that there was no email present other than the app just stalling out and doing nothing?

It turns out that serviceConfig.getEmailAddress(); throws an exception if there is no email registered. There is no mention of this in the BlackBerry documentation. It is also strange because if you do not catch that exception the method just never returns and your application will stall indefinitely. But to fix you can just surround that call with try/catch and set the email to default in the catch block.
Would have saved me a lot of time if this was actually documented correctly. I am hopefully that posting the answer here will save someone from chasing something that is undocumented.

Related

How to detect absent network connection when setting Firestore document

We are building a real-time chat app using Firestore. We need to handle a situation when Internet connection is absent. Basic message sending code looks like this
let newMsgRef = database.document(“/users/\(userId)/messages/\(docId)“)
newMsgRef.setData(payload) { err in
if let error = err {
// handle error
} else {
// handle OK
}
}
When device is connected, everything is working OK. When device is not connected, the callback is not called, and we don't get the error status.
When device goes back online, the record appears in the database and callback triggers, however this solution is not acceptable for us, because in the meantime application could have been terminated and then we will never get the callback and be able to set the status of the message as sent.
We thought that disabling offline persistence (which is on by default) would make it trigger the failure callback immediately, but unexpectedly - it does not.
We also tried to add a timeout after which the send operation would be considered failed, but there is no way to cancel message delivery when the device is back online, as Firestore uses its queue, and that causes more confusion because message is delivered on receiver’s side, while I can’t handle that on sender’s side.
If we could decrease the timeout - it could be a good solution - we would quickly get a success/failure state, but Firebase doesn’t provide such a setting.
A built-in offline cache could be another option, I could treat all writes as successful and rely on Firestore sync mechanism, but if the application was terminated during the offline, message is not delivered.
Ultimately we need a consistent feedback mechanism which would trigger a callback, or provide a way to monitor the message in the queue etc. - so we know for sure that the message has or has not been sent, and when that happened.
The completion callbacks for Firestore are only called when the data has been written (or rejected) on the server. There is no callback for when there is no network connection, as this is considered a normal condition for the Firestore SDK.
Your best option is to detect whether there is a network connection in another way, and then update your UI accordingly. Some relevant search results:
Check for internet connection with Swift
How to check for an active Internet connection on iOS or macOS?
Check for internet connection availability in Swift
As an alternatively, you can check use Firestore's built-in metadata to determine whether messages have been delivered. As shown in the documentation on events for local changes:
Retrieved documents have a metadata.hasPendingWrites property that indicates whether the document has local changes that haven't been written to the backend yet. You can use this property to determine the source of events received by your snapshot listener:
db.collection("cities").document("SF")
.addSnapshotListener { documentSnapshot, error in
guard let document = documentSnapshot else {
print("Error fetching document: \(error!)")
return
}
let source = document.metadata.hasPendingWrites ? "Local" : "Server"
print("\(source) data: \(document.data() ?? [:])")
}
With this you can also show the message correctly in the UI

return null notificationId in NotificationHub

I use Microsoft.Azure.NotificationHubs in VS2017. when I try to send a notification by SendAppleNativeNotificationAsync method this doesn't return notificationId, this is null. I have the Standard pricing for Notification Hub
enter image description here
Are you using Test Send by any chance? Please note that NotificationId is returned NULL while doing a test send. This is because you can get the result of Send operation in the output of Send* method itself. NotificationOutcome.Results property will have list of registrations this Send* was sent to. (Note that test sends are only meant for troubleshooting purposes and they target a maximum of 10 devices. Read through the above post for more info).
I worked with REST API I did a simple test and it worked correctly Send an APNS Native Notification, azure-notificationhubs here I found everything necessary for my problem

Apache Commons Email work with "normal gmail", but not "Gmail for work"?

Hi I'm using the following code to send email:
public static void sendEmail(String from, String to, String password) {
Email email = new SimpleEmail();
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator(from, password));
email.setSSLOnConnect(true);
email.setSubject("Plain mail");
email.setMsg("test");
email.addTo(to);
email.send();
}
Now, it works when I'm calling this function with my "normal" gmail address:
sendMail("me#gmail.com","friend#gmail.com", "my-password");
So the above works. But when I'm trying to migrate to Gmail for Business, and create an email address "me#mycompany.com" (which is hooked to Gmail), I get an authentication error:
sendMail("me#mycompany.com","friend#gmail.com", "my-new-password");
Gives me this error:
javax.mail.AuthenticationFailedException:
<https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsb...ZlTLN2wQG4>
Please log in via your web browser and then try again.
I suspect I need to set something in my Google Apps console, but I'm not even sure where to start looking for the info.
Can anybody help?
Thanks.
This answer is coming from a similar SO question here.
The issue is due to allowing less secure apps to access your account. Click the following link https://www.google.com/settings/security/lesssecureapps and disable security setting. For more information you can read this here.
Good luck!

How to check whether E-Mail was successfully sent in Liferay 6.1.20EE via MailServiceUtil

I'm using Liferay 6.1.20 and my Portlet is using the Liferay Mail Service to send an E-Mail via the in Liferay configured SMTP-Server.
My Question is now: is it possible to check whether the SMTP-Server is available or is it possbile to check whether the E-Mail was successfully sent? If the SMTP-Server is not available I want to give an output to the User. Actually I only see the following line in the server console:
14:06:47,679 WARN [liferay/mail-1][MailEngine:560] Failed to connect to a valid mail server. Please make sure one is properly configured. Could not connect to SMTP host: localhost, port: 25
I hope someone can give me a solution for that. Thanks!
basically there are two problems which prevent you to discover if any failure occurred when sending e-mails with MailServiceUtil service.
Firstly messages are sent asynchronously over Liferay message bus, so the user gets faster response but you never know if anything failed on the way.
Secondly messages eventually get to MailEngine where all exceptions get caught and are only written to the log.
So, I suggest you to override MailEngine class with ext-plugin (it's in util-java) to handle exceptions differently and then use it directly from your plugin instead of MailServiceUtil which only pushes all to the message bus.
Since Liferay 6.2, if you set mail.throws.exception.on.failure=true in your portal-ext.properties file, the MailEngine class will also throw a com.liferay.util.mail.MailEngineException on errors, instead of just logging.
A really old question, but as I kept arriving here, I am leaving this to anyone that may need (tested on 7.3).
We can test if the mail flow is normal with the following Groovy script:
import com.liferay.mail.kernel.service.MailServiceUtil
import javax.mail.*
import javax.mail.internet.*
import com.liferay.mail.kernel.model.MailMessage;
def from = new InternetAddress("no-reply#example.com")
def to = new InternetAddress ("where#example.com")
def mail = new MailMessage(from, to, "subject", "test message", false)
MailServiceUtil.sendEmail(mail)
And, as mentioned in the other answer, the property to view exceptions is still valid.
mail.throws.exception.on.failure=true

load magento email template

I'm using my own code to send out SMS's to the customers at the same time as the emails go out. I do this by getting the email template code with
$code = $this->getTemplateCode();
and then trying to load the corresponding SMS template with
$sms = $this->loadByCode('sms_'.$code)->getTemplateText();
I then check if $sms is empty before proceeding to send the text, meaning that I can add or remove connected SMS templates at will. The problem I'm having is that I sometimes, when there is no connected "sms_*" template, I get the full email sent out as the SMS instead of no text being sent.
I've debugged the code by sending out the template it tries to load as the actual SMS, and received "sms_creditmemo", but when I instead load it with the method above and do a var_dump($sms); exit;it shows me that it loaded the template "creditmemo_invoice" which is the email template I use instead of "creditmemo" when the payment method is detected. I make sure to use the original template string in $code (used to load SMS template) no matter the payment method.
Now my question would be how this can even be possible, does the loadByCode take best matching template or is there some other more serious bug I've missed, maybe there's better ways to load in the templates and make correct checks to see if they even exist?
I solved this by checking if the correct email template gets loaded with
if ($this->loadByCode($template)->getTemplateCode() == $template)