QT创建者发送短信

QT Creator send SMS message

本文关键字:创建者 QT      更新时间:2023-10-16

>无法弄清楚如何使用在 Ubuntu 16.04 上运行的 QT Creator 向手机发送短信。 可以使用 MS 视觉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

8个小时的脑痛就解决了。要使用 QTcreator(在我的情况下为 5.5)执行与上述相同的操作,除了在 Ubuntu(在我的例子中为 16.04)中,并将最令人发指、最可憎和真正令人作呕的 C# 代码替换为纯粹、高贵和美丽的C++,请执行以下操作:
使用时代华纳 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,时代华纳私下使用 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()  << "rn";
*t << QByteArray().append(user)  << "rn";  //Time Warner doesn't use base64

有了这个,可以从UI发送电子邮件。 要向维珍移动发送短信,请将收件人替换为 10 位数的电话号码 @vmobl.com。 示例:"7609999999@vmobl.com"。 短信将是"主题:"加上主题。 正文不会出现,因此留空。 一开始我找不到简单的方法来摆脱"主题:"。