c++ 如何发送短信

vzgqcmou  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(152)

我不知道如何在Ubuntu 16.04上运行Qt向手机发送短信。
下面的代码在Windows Visual C++/CLI中运行良好。在Ubuntu 16.04上的Qt中是否有等效的代码?

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("[email protected]"); //the generic Virgin Mobile format
MailAddress^ from = gcnew MailAddress("[email protected]"); //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

字符串

58wvjzkj

58wvjzkj1#

要执行与上述操作相同的操作(除了在Ubuntu(在我的示例中为16.04)中使用Qt(在我的示例中为5.5)之外),并将C#代码替换为C++,请执行以下操作:
使用Time-Warner SMTP服务器(而不是Gmail服务器):
1.转到Github: xcoder123 / SimpleSmtp_SSL_QT5
1.下载,克隆或解压缩;然后在QT中打开这个优秀的项目

  • 在smtp.h中进行以下更改:
  • 添加此以与Time Warner Cable:
#include <QtNetwork/QTcpSocket>

配合使用

  • 在公开场合:Smtp将int port = 465改为int port = 587,gmail使用465,时代华纳使用587。
  • 私下里:
//QSslSocket *socket;  //this works with Gmail
 QTcpSocket *socket;    //this works with Time Warner Cable
  • smtp.cpp 中进行以下更改:
  • Smtp::Smtp中:
//socket = new QSslSocket(this);  //this works with Gmail
socket = new QTcpSocket(this);    //this works with Time Warner Cable
  • void Smtp::sendMail中:
//socket->connectToHostEncrypted(host, port); //"smtp.gmail.com" and 465 for gmail TLS
socket->connectToHost(host, port);  //Time Warner doesn't use Encrypted
  • void 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

这样,就可以从用户界面发送电子邮件。
要向维珍移动的发送短信,请将收件人替换为10位数得电话号码 @vmobl.com.
范例:

  • email protected(https://stackoverflow.com/cdn-cgi/l/email-protection)“的值。

文本消息将是“Subject:“加上主题。正文不会显示,因此请将其留空。我找不到简单的方法来删除开头的“Subject:“。

相关问题