Mailer Error on sending mail with Flutter - email

I'm actually developping a mobile app with Flutter and I wish I could send an email from it. To do so, i tried to use the Mailer plugin with the following code :
import 'package:flutter/material.dart';
import 'package:mailer2/mailer.dart';
main() {
var options = new GmailSmtpOptions()
..username = 'mer*******#gmail.com'
..password = '*******';
var emailTransport = new SmtpTransport(options);
// Create our mail/envelope.
var envelope = new Envelope()
..from = 'mer*******#gmail.com'
..recipients.add('*******#*****.fr')
..subject = 'Testing the Dart Mailer library'
..text = 'This is a cool email message. Whats up? 語'
..html = '<h1>Test</h1><p>Hey!</p>';
// Email it.
emailTransport.send(envelope)
.then((envelope) => print('Email sent!'))
.catchError((e) => print('Error occurred: $e'));
}
However, i have the following error:
I/flutter (22531): Error occurred: type '_AsBroadcastStream<dynamic>' is not a subtype of type 'Stream<Envelope>' where
I/flutter (22531): _AsBroadcastStream is from dart:async
I/flutter (22531): Stream is from dart:async
I/flutter (22531): Envelope is from package:mailer/mailer.dart
Can someone help me ? Thanks in advance !

In this file
mailer-1.1.4/lib/src/smtp/smtp_client.dart
Update lines 49 & 50 by add "cast()" method to be:
onIdle = _onIdleController.stream.asBroadcastStream().cast();
onSend = _onSendController.stream.asBroadcastStream().cast();

Related

Call not working sometimes in sip_ua package of Dart

I'm Developing VOIP application in Flutter. Got below error and call not connected not in every case but in random case its happen.
Sip Registration Snippet
static void registeredSip(SipData sp) async {
UaSettings settings = UaSettings();
settings.webSocketUrl = 'wss://${sp.sipDomin}:${sp.sipPort}';
settings.webSocketSettings.allowBadCertificate = true;
var uri = 'sip:${sp.sipUsername}#${sp.sipDomin}';
settings.uri = uri;
settings.authorizationUser = sp.sipUsername;
settings.password = sp.sipPassword;
settings.displayName = sp.sipUsername;
globals.helper!.start(settings);
}
Starting Sip Call snippets below
SIPUAHelper helperObj = globals.helper!;
helperObj.call(typedNumber,voiceonly: true, mediaStream: null);
Error
sip_ua_helper.dart:224 ::: call failed with cause: Code: [408], Cause: Canceled, Reason: SIP ;cause=408 ;text="Request Timeout"
I'm using Sip_ua for Calling.

how to send file Attachment by Mail In Flutter

hello i'm trying to send email with attachment using mailer flutter so i i specified the file path but when the email is sent i find just the text without the attachment what is wrong ? . this the code :
final equivalentMessage = Message()
..from = Address(username, '***** ')
..recipients.add(Address('********'))
//..ccRecipients.addAll([Address('destCc1#example.com'), 'destCc2#example.com'])
//..bccRecipients.add('bccAddress#example.com')
..subject = 'Test Dart Mailer library :: 😀 :: ${DateTime.now()}'
..text = 'This is the plain text.\nThis is line 2 of the text part.'
..html =
'<h1>Test</h1>\n<p>Hey! Here is some HTML content</p><img src="cid:myimg#3.141"/>'
..attachments = [
FileAttachment(File('/path/hello.txt'))
];

Any help on chatterbot error: module 'time' has no attribute 'clock' error (python 3.10.1)

from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
bot = ChatBot('Bot')
trainer = ListTrainer(bot)
trainer.train([
'Hi how can I help you?',
'howdy?',
'hello?'
])
while True:
request = input('You: ')
response = bot.get_response(request)
print('Bot: ', response)
The problem is on this control of the file of compact.py, you need to modify it from:
if win32 or jython:
time_func = time.clock
else:
time_func = time.time
to:
if win32 or jython:
try:
preferred_clock = time.perf_counter
except AttributeError:
preferred_clock = time.clock
else:
time_func = time.time

CERTIFICATE_VERIFY_FAILED when trying to import data from API

I'm trying to learn Flutter/Dart and I'm having to much problems. Now I'm trying to obtain some values from an API. My code is:
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:myapp01_apirequest/src/models/uplink_models.dart';
class UplinksProvider{
String _url = 'xxx.yyy.com';
Future<List<Uplink>> getEnCines() async{
try{
final url = Uri.https(_url, ':14442/api/external/login', {
'username': 'Joe689',
'password': '15.Job_1825zz'
});
final resp = await http.get(url);
final decodedData = json.decode(resp.body);
print('Patata');
print(decodedData);
return [];
}catch (error){
print('++++++++++///////++++++++++++++++');
print(error);
print('++++++++++*******++++++++++++++++');
}
}
}
Reading the Uri constructor documentation I understood that I have to split in 3 my url.
First one is authority. In my case I think is xxx.yyy.com.
Second is the unencodedPath. In my case I think is :14442/api/external/login.
Finally a map with params in my case the username and pass (the only thing I'm pretty sure is correct in my code).
If I do this, any problem appears, but the print('Patata'); and print(decodeData); don't appear. In addition, a file called io_client.dart opens and marks the next line.
var ioRequest = (await _inner.openUrl(request.method, request.url))
The console shows nothing (I think):
Launching lib\main.dart on LG M700 in debug mode...
lib\main.dart:1
Formato de par�metros incorrecto:
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:55883/KBAtv2-Jljc=/ws
Why no errors appears but I can't obtain my desired data?
EDIT:
According for what #Preet Shah's said I press the "VS run button" and appears the following exception three times:
I/flutter ( 1932): ++++++++++///////++++++++++++++++
I/flutter ( 1932): HandshakeException: Handshake error in client (OS Error:
I/flutter ( 1932): CERTIFICATE_VERIFY_FAILED: Hostname mismatch(handshake.cc:354))
I/flutter ( 1932): ++++++++++*******++++++++++++++++
And finally appears:
I/Choreographer( 1932): Skipped 148531 frames! The application may be doing too much work on its main thread.
D/vndksupport( 1932): Loading /vendor/lib/hw/android.hardware.graphics.mapper#2.0-impl.so from current namespace instead of sphal namespace.
D/vndksupport( 1932): Loading /vendor/lib/hw/gralloc.msm8937.so from current namespace instead of sphal namespace.
I/Choreographer( 1932): Skipped 35 frames! The application may be doing too much work on its main thread.
Then the problem is a certification problem, CERTIFICATE_VERIFY_FAILED. As I feel more comfortable with python, I have done some tests to understand the problem. I have been able to verify that this API requires having all the certification verifications in false, otherwise it never leaves the loop. Here is my Python code (just to show what I'm saying).
import requests
import json
log_params = {'username': 'Joe689', 'password': '15.Job_1825zz'}
headers = {'Content-type': 'application/json'}
url = 'https://xxx.yyy.com:14442/api/external/login'
response = requests.post(url, data=json.dumps(params), headers=self.headers, verify=False)
finalRes = json.loads(response.text)
As I said, this code is just for me to understand the problem because I am a newbie to Dart. Here I found this answer and it seems has the solution but I don't know how to implement it, using my Uri.https estructure (maybe it's not possible).
I tried this, but isn't working:
Map<String, String> requestHeaders = {
'Content-type': 'application/json'
};
final resp = await http.get(url, headers:requestHeaders);
Thank you very much.
Try this:
HttpClient client = new HttpClient();
client.badCertificateCallback = ((X509Certificate cert, String host, int port) => true);
String url ='xxx.yyy.com:14442/api/external/login';
Map map = {
"email" : "Joe689" ,
"password" : "15.Job_1825zz"
};
HttpClientRequest request = await client.getUrl(Uri.parse(url));
request.headers.set('content-type', 'application/json');
request.add(utf8.encode(json.encode(map)));
HttpClientResponse response = await request.close();
String reply = await response.transform(utf8.decoder).join();
print(reply);
Now, check what reply contains. And accordingly, return the data.

Zend Mail keeps giving me a Socket Error

I'm having trouble with sending email using the zend framework. I keep getting a "Could not open socket" error.
I don't know whats wrong here - it used to work on my other host. Ever since I shifted it to another host I can't send emails. I've set up the configuration values to match the new email server.
Heres my code:
$config = array('auth' => _config('mail', 'auth'),
'username' => _config('mail', 'email'),
'password' => _config('mail', 'password'));
$tr = new Zend_Mail_Transport_Smtp(_config('mail', 'smtp'), $config);
$mail = new Zend_Mail();
$mail->setDefaultTransport($tr);
$mail->setFrom(_config('mail','email'), _config('mail','name'));
$mail->addTo($account_email);
$mail->setSubject($mailTitle);
$mail->setBodyText($mailContent);
$mail->send($tr);
EDIt ===
Well the code posted above is my actual code - I don't know whats wrong with it as it used to work on another host.
The following is the exact error I'm getting
Could not open socketstring(1237) "#0 /home/india/public_html/demo/library/Zend/Mail/Protocol/Smtp.php(167): Zend_Mail_Protocol_Abstract->_connect('tcp://mail.indi...')
#1 /home/india/public_html/demo/library/Zend/Mail/Transport/Smtp.php(199): Zend_Mail_Protocol_Smtp->connect()
#2 /home/india/public_html/demo/library/Zend/Mail/Transport/Abstract.php(348): Zend_Mail_Transport_Smtp->_sendMail()
#3 /home/india/public_html/demo/library/Zend/Mail.php(1194): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail))
#4 /home/india/public_html/demo/application/controllers/AccountController.php(2153): Zend_Mail->send(Object(Zend_Mail_Transport_Smtp))
#5 /home/india/public_html/demo/library/Zend/Controller/Action.php(513): AccountController->forgetPasswordAction()
#6 /home/india/public_html/demo/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('forgetPasswordA...')
#7 /home/india/public_html/demo/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#8 /home/india/public_html/demo/application/bootstrap.php(26): Zend_Controller_Front->dispatch() #9 /home/india/public_html/demo/html/index.php(4): Bootstrap::run() #10 {main}"
marhaba Ali! ,
digging the code of Zend mail shows http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Mail/Protocol/Abstract.php
protected function _connect($remote)
{
$errorNum = 0;
$errorStr = '';
// open connection
$this->_socket = #stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);
if ($this->_socket === false) {
if ($errorNum == 0) {
$errorStr = 'Could not open socket';
}
/**
* #see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception($errorStr);
}
if (($result = $this->_setStreamTimeout(self::TIMEOUT_CONNECTION)) === false) {
/**
* #see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('Could not set stream timeout');
}
return $result;
}
and usually the error number 0 because of
if ($errorNum == 0) {
$errorStr = 'Could not open socket';
}
from : http://php.net/manual/en/function.stream-socket-client.php
On failure the errno and errstr
arguments will be populated with the
actual system level error that
occurred in the system-level connect()
call. If the value returned in errno
is 0 and the function returned FALSE,
it is an indication that the error
occurred before the connect() call.
This is most likely due to a problem
initializing the socket. Note that the
errno and errstr arguments will always
be passed by reference.
I guess its some firewall blocking the connection to be sent out ,
system-level or network-level error
If you update your answer with more detailed info , i would be happy to help