无法弄清楚如何使用在Ubuntu 16.04上运行的QT Creator将短信发送到手机。可以轻松使用MS Visual C ++
下面的代码在Windows Visual C ++ / CLI中可以正常工作。在Ubuntu 16.04上的QT Creator中是否有与此等效的代码或某些等效代码?
using namespace System::Net; //need for Webclient
using namespace System::Net::Mail; //need for sending SMS text message via email
//send an SMS message via email:
MailAddress^ to = gcnew MailAddress("760xxxxxxx@vmobl.com"); //the generic Virgin Mobile format
MailAddress^ from = gcnew MailAddress("xxxxxxxx@roadrunner.com"); //hosted by Time Warner Cable
MailMessage^ message = gcnew MailMessage(from,to);
message->Subject = "What's up?"; //the subject line
message->Body = Globals::TextMsg; //TestMsg is a string; the body of the message to be sent
SmtpClient^ client = gcnew SmtpClient; //create a client
client->Host::set("mail.twc.com"); //the outgoing SMTP mail server of Time Warner
client->Send(message); //send message to phone
client->~SmtpClient(); //destroy the client
答案 0 :(得分:1)
8小时的脑部疼痛得到了解决。要执行与上述相同的操作,除了在Ubuntu(在我的情况下为16.04)和QTcreator(在我的情况下为5.5)中,并用纯净,高贵和美丽的C ++替换最令人发指,可憎的和令人恶心的C#代码,请执行以下操作:
使用Time-Warner SMTP服务器(而不是Gmail服务器):
1.转到https://github.com/xcoder123/SimpleSmtp_SSL_QT5/tree/master/smtp
2.下载,克隆或解压缩;然后在QT中打开这个出色的项目
3.在smtp.h中进行以下更改:
#include <QtNetwork/QTcpSocket> //add this to work with Time Warner Cable
''
在公共场合:将Smtp的'int port = 465'更改为'int port = 587'// gmail使用465,Time Warner使用587
私下:
//QSslSocket *socket; //this works with Gmail
QTcpSocket *socket; //this works with Time Warner Cable
4.在smtp.cpp中进行以下更改:
在Smtp :: Smtp
中
//socket = new QSslSocket(this); //this works with Gmail
socket = new QTcpSocket(this); //this works with Time Warner Cable
在无效的Smtp :: sendMail
中
//socket->connectToHostEncrypted(host, port); //"smtp.gmail.com" and 465 for gmail TLS
socket->connectToHost(host, port); //Time Warner doesn't use Encrypted
在无效的Smtp :: readyRead
中
//socket->startClientEncryption(); //Time Warner doesn't use Encryption, so comment all this out
// if(!socket->waitForEncrypted(timeout))
// {
// qDebug() << socket->errorString();
// state = Close;
// }
//*t << QByteArray().append(user).toBase64() << "\r\n";
*t << QByteArray().append(user) << "\r\n"; //Time Warner doesn't use base64
这样,可以从UI发送电子邮件。要将短信发送到Virgin Mobile,请将收件人替换为10位数的电话号码@ vmobl.com。例如:“ 7609999999@vmobl.com”。短信为“主题:”加上主题。主体将不会显示,因此请留空。我一开始就找不到摆脱“主题:”的简单方法。