예제 #1
0
//--------------------------------------------------------------
void testApp::keyPressed(int key){
	if(key!=27)
	{
	ofxMailMessage message;
	message.recipients.push_back("recipients");
	message.sender="sender";
	message.subject="subject of the message";
	message.content = "Hello World";
	message.attachmentPaths.push_back( "image1.png");
	message.date=Poco::Timestamp();
	ofxSmtpClientUtils smtp ("127.0.0.1",1199,"account","password");
//	smtp.addMessage(message);
	smtp.sendMessage(message);
	cout << "testApp::keyPressed: new message sent\n";
	
	}
}
void ConnectionTest::testConnect() {
    QFETCH(QString, host);
    QFETCH(int, port);
    QFETCH(int, connectionType);

    const SmtpClient::ConnectionType cTypes[] = {
        SmtpClient::TcpConnection,
        SmtpClient::SslConnection,
        SmtpClient::TcpConnection
    };

    SmtpClient::ConnectionType cType = cTypes[--connectionType];

    SmtpClient smtp(host, port, cType);
    smtp.connectToHost();

    QCOMPARE(smtp.waitForReadyConnected(5000), true);
}
예제 #3
0
파일: compose.cpp 프로젝트: bomboom/foxmail
void compose::contextSendButton()
{
    QString str=Toedit->text();
    rcpts=str.split(";");    //邮件接受者地址以";"分隔
    ccs=Ccedit->text().split(";");
    bccs=Bccedit->text().split(";");
    QStringList to=rcpts+ccs+bccs;

    //QString host=ui->host->text();
    //int port=25;
    QString host, password, sender;
    int port;
    QString user=from->currentText();
    QString portstr;
    QFile file("account.txt");

    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
       QString read;
       QStringList str;

       while(!file.atEnd())
       {
            read=file.readLine();
            str=read.split(" ");
            if(user.compare(str.at(0))==0)
            {
                sender=str.at(0);
                //Ccedit->setText(sender);
                password=str.at(1);
                //Bccedit->setText(password);
                host = str.at(6);
                //qDebug()<<host<<"host";
                portstr=str.at(7);
                //qDebug()<<portstr<<"port";
                break;
            }
       }
     }
    file.close();
    bool ok1;
    ok1=true;
    port=portstr.toInt(&ok1,10);
    //qDebug()<<port;
    //QString password=ui->password->text();
    //QString sender=Toedit->text();
    QString subject=Subjectedit->text();
    QString content=letter->toPlainText();         //接收ui中输入的内容

   MailContent email(sender,rcpts,ccs,bccs,subject,content);

    for (int i = 0; i < attachlist->count(); ++i)
    {
        email.addAttachment(new Attachment(new QFile(attachlist->item(i)->text())));
    }

    Smtp smtp(host,port,user,password,sender,to);
    smtp.connectToHost();
    smtp.login();

    tipDialog *tipdialog = new tipDialog(this);
    tipdialog->setWindowModality(Qt::ApplicationModal);
    tipdialog->setQString("Sending....");
    tipdialog->show();

    QCoreApplication::processEvents();

    if(smtp.sendMail(email))
    {
        tipdialog->setQString("Send Successfully");
        smtp.saveSendMail(email, "sent");
    }else
    {
        tipdialog->setQString("Send Failed");
        smtp.saveSendMail(email, "draft");
    }

    smtp.quit();


}
예제 #4
0
/*------------------------------------------------------------------------------*\
	MessageReceived( msg)
		-	
\*------------------------------------------------------------------------------*/
void BmPrefsSendMailView::MessageReceived( BMessage* msg) {
	try {
		switch( msg->what) {
			case BM_SELECTION_CHANGED: {
				int32 index = mAccListView->CurrentSelection( 0);
				ShowAccount( index);
				break;
			}
			case BM_TEXTFIELD_MODIFIED: {
				if (mCurrAcc) {
					BView* srcView = NULL;
					msg->FindPointer( "source", (void**)&srcView);
					BmTextControl* source = dynamic_cast<BmTextControl*>( srcView);
					if ( source == mAccountControl) {
						BmString oldName = mCurrAcc->Name();
						BmString newName = mAccountControl->Text();
						TheSmtpAccountList->RenameItem( oldName, newName);
						BmModelItemMap::const_iterator iter;
						// update any links to this smtp-account:
						BAutolock lock( TheIdentityList->ModelLocker());
						for( 	iter = TheIdentityList->begin(); 
								iter != TheIdentityList->end(); ++iter) {
							BmIdentity* ident 
								= dynamic_cast<BmIdentity*>( iter->second.Get());
							if (ident && ident->SMTPAccount()==oldName)
								ident->SMTPAccount( newName);
						}
					} else if ( source == mDomainControl)
						mCurrAcc->DomainToAnnounce( mDomainControl->Text());
					else if ( source == mLoginControl)
						mCurrAcc->Username( mLoginControl->Text());
					else if ( source == mPortControl)
						mCurrAcc->PortNr( uint16(atoi(mPortControl->Text())));
					else if ( source == mPwdControl)
						mCurrAcc->Password( mPwdControl->Text());
					else if ( source == mServerControl)
						mCurrAcc->SMTPServer( mServerControl->Text());
					else if ( source == mClientCertControl)
						mCurrAcc->ClientCertificate( mClientCertControl->Text());
					NoticeChange();
					UpdateState();
				}
				break;
			}
			case BM_PWD_STORED_CHANGED: {
				if (mCurrAcc) {
					mCurrAcc->PwdStoredOnDisk( mStorePwdControl->Value());
					NoticeChange();
				}
				UpdateState();
				break;
			}
			case BM_ENCRYPTION_SELECTED: {
				EncryptionSelected();
				NoticeChange();
				UpdateState();
				break;
			}
			case BM_AUTH_SELECTED: {
				AuthTypeSelected();
				NoticeChange();
				UpdateState();
				break;
			}
			case BM_CHECK_AND_SUGGEST: {
				if (mCurrAcc) {
					// ToDo: this should be made asynchronous (using messages):
					BmRef<BmSmtp> smtp( new BmSmtp( mCurrAcc->Key(), 
															  mCurrAcc.Get()));
					smtp->StartJobInThisThread( BmSmtp::BM_CHECK_CAPABILITIES_JOB);
					BmString suggestedAuthType = smtp->SuggestAuthType();
					if (suggestedAuthType.Length())
						mAuthControl->MarkItem( suggestedAuthType.String());
					else
						mAuthControl->MarkItem( BM_NoItemLabel.String());
					AuthTypeSelected();
					if (smtp->SupportsTLS())
						mEncryptionControl->MarkItem( BmSmtpAccount::ENCR_STARTTLS);
					else
						mEncryptionControl->MarkItem( BM_NoItemLabel.String());
					EncryptionSelected();
					NoticeChange();
					UpdateState();
				}
				break;
			}
			case BM_CLIENT_CERT_SELECTED: {
				entry_ref certRef;
				if (msg->FindRef( "refs", 0, &certRef) != B_OK) {
					// first step, let user select new certificate:
					if (!mClientCertPanel) {
						BmString certPath = TheNetEndpointRoster->GetCertPath();
						entry_ref eref;
						status_t err = get_ref_for_path(certPath.String(), &eref);
						mClientCertPanel = new BFilePanel( 
							B_OPEN_PANEL, new BMessenger(this), 
							err == B_OK ? &eref : NULL, B_FILE_NODE, false, msg
						);
					}
					mClientCertPanel->Show();
				} else {
					// second step, set data accordingly:
					mCurrAcc->ClientCertificate(certRef.name);
					mClientCertControl->SetText(certRef.name);
					NoticeChange();
					UpdateState();
				}
				break;
			}
			case BM_CLEAR_ACCEPTED_CERT: {
				mCurrAcc->AcceptedCertID("");
				mAcceptedCertControl->SetText("");
				NoticeChange();
				break;
			}
			case BM_POP_SELECTED: {
				BMenuItem* item = mPopControl->Menu()->FindMarked();
				if (item && BM_NoItemLabel != item->Label())
					mCurrAcc->AccForSmtpAfterPop( item->Label());
				else
					mCurrAcc->AccForSmtpAfterPop( "");
				NoticeChange();
				UpdateState();
				break;
			}
			case BM_ADD_ACCOUNT: {
				BmString key( "new account");
				for( int32 i=1; TheSmtpAccountList->FindItemByKey( key); ++i) {
					key = BmString("new account_")<<i;
				}
				TheSmtpAccountList->AddItemToList( new BmSmtpAccount( key.String(), 
															  TheSmtpAccountList.Get()));
				mAccountControl->MakeFocus( true);
				mAccountControl->TextView()->SelectAll();
				NoticeChange();
				break;
			}
			case BM_REMOVE_ACCOUNT: {
				int32 buttonPressed;
				if (msg->FindInt32( "which", &buttonPressed) != B_OK) {
					// first step, ask user about it:
					BAlert* alert = new BAlert( 
						"Remove Mail-Account", 
					 	(BmString("Are you sure about removing the account <") 
					 		<< mCurrAcc->Name() << ">?").String(),
						"Remove", "Cancel", NULL, B_WIDTH_AS_USUAL,
						B_WARNING_ALERT
					);
					alert->SetShortcut( 1, B_ESCAPE);
					alert->Go( new BInvoker( new BMessage(BM_REMOVE_ACCOUNT), 
													 BMessenger( this)));
				} else {
					// second step, do it if user said ok:
					if (buttonPressed == 0) {
						TheSmtpAccountList->RemoveItemFromList( mCurrAcc.Get());
						mCurrAcc = NULL;
						NoticeChange();
					}
				}
				break;
			}
			case BM_COMPLAIN_ABOUT_FIELD: {
				int32 buttonPressed;
				if (msg->FindInt32( "which", &buttonPressed) != B_OK) {
					BmString complaint;
					complaint = msg->FindString( MSG_COMPLAINT);
					// first step, tell user about complaint:
					BAlert* alert = new BAlert( "Sanity Check Failed", 
														 complaint.String(),
													 	 "OK", NULL, NULL, B_WIDTH_AS_USUAL,
													 	 B_WARNING_ALERT);
					alert->SetShortcut( 0, B_ESCAPE);
					alert->Go( new BInvoker( new BMessage(*msg), BMessenger( this)));
					BmSmtpAccount* acc=NULL;
					msg->FindPointer( MSG_ITEM, (void**)&acc);
					BmListViewItem* accItem = mAccListView->FindViewItemFor( acc);
					if (accItem)
						mAccListView->Select( mAccListView->IndexOf( accItem));
				} else {
					// second step, set corresponding focus:
					BmString fieldName;
					fieldName = msg->FindString( MSG_FIELD_NAME);
					if (fieldName.ICompare( "username")==0)
						mLoginControl->MakeFocus( true);
					else if (fieldName.ICompare( "smtpserver")==0)
						mServerControl->MakeFocus( true);
					else if (fieldName.ICompare( "pop-account")==0)
						mPopControl->MakeFocus( true);
					else if (fieldName.ICompare( "portnr")==0)
						mPortControl->MakeFocus( true);
				}
				break;
			}
			default:
				inherited::MessageReceived( msg);
		}
	}
	catch( BM_error &err) {
		// a problem occurred, we tell the user:
		BM_SHOWERR( BmString("PrefsView_") << Name() << ":\n\t" << err.what());
	}
}
예제 #5
0
int main( int argc, char * argv[] )
{
	std::string qqnumber, qqpwd;
	std::string ircnick, ircroom, ircpwd;
	std::string xmppuser, xmppserver, xmpppwd, xmpproom;
	std::string cfgfile;
	std::string logdir;
	std::string chanelmap;
	std::string mailaddr, mailpasswd, mailserver;

	setlocale( LC_ALL, "" );

	po::options_description desc( "qqbot options" );
	desc.add_options()
	( "version,v",										"output version" )
	( "help,h",											"produce help message" )
	( "daemon,d",										"go to background" )
	( "mail",		po::value<std::string>( &mailaddr ),	"send mail by this address" )
	( "mailpasswd",	po::value<std::string>( &mailpasswd ), "password of mail" )
	( "mailserver",	po::value<std::string>( &mailserver ), "server to use" )
	;

	po::variables_map vm;
	po::store( po::parse_command_line( argc, argv, desc ), vm );
	po::notify( vm );

	if( vm.count( "help" ) ) {
		std::cerr <<  desc <<  std::endl;
		return 1;
	}

	if( vm.size() == 0 ) {
		try {
			fs::path p = configfilepath();
			po::store( po::parse_config_file<char>( p.string().c_str(), desc ), vm );
			po::notify( vm );
		} catch( char* e ) {
			std::cerr << e << std::endl;
		}
	}

	boost::asio::io_service io;
	mx::smtp smtp( io, mailaddr, mailpasswd, mailserver );
	InternetMailFormat imf;

	imf.header["from"] = mailaddr;
	imf.header["to"] = "\"晕菜\" <*****@*****.**>";
	imf.header["subject"] = "test mail";
	imf.header["content-type"] = "text/plain; charset=utf8";

	imf.body = "test body dasdfasd ";
	std::stringstream maildata;
	boost::asio::streambuf buf;
	std::ostream os( &buf );
	imf_write_stream( imf, os );

	std::string _mdata = boost::asio::buffer_cast<const char*>( buf.data() );

	smtp.async_sendmail( imf, sended );
	io.run();
}
예제 #6
0
int
main (int argc, char *argv[])
{
  const char *service = argc > 1 ? argv[1] : "2000";
  volatile int run = 1;
  struct addrinfo hints, *addrs;
  int sockfd;
  int rc;
  int yes = 1;
  Gsasl *ctx;
  struct cfg cfg;

  setvbuf (stdout, NULL, _IONBF, 0);

  if (argc != 7)
    {
      printf ("Usage: %s PORT CFG-PATH STATE-PATH SP-METADATA "
	      "SP-KEY SP-CERT\n", argv[0]);
      exit (EXIT_FAILURE);
    }
  cfg.cfg_path = argv[2];
  cfg.state_path = argv[3];
  cfg.sp_metadata = argv[4];
  cfg.sp_key = argv[5];
  cfg.sp_cert = argv[6];

  rc = gsasl_init (&ctx);
  if (rc < 0)
    {
      printf ("gsasl_init (%d): %s\n", rc, gsasl_strerror (rc));
      exit (EXIT_FAILURE);
    }

  printf ("%s [gsasl header %s library %s]\n",
	  argv[0], GSASL_VERSION, gsasl_check_version (NULL));

  gsasl_callback_set (ctx, callback);
  gsasl_callback_hook_set (ctx, &cfg);

  memset (&hints, 0, sizeof (hints));
  hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
  hints.ai_socktype = SOCK_STREAM;

  rc = getaddrinfo (NULL, service, &hints, &addrs);
  if (rc < 0)
    {
      printf ("getaddrinfo: %s\n", gai_strerror (rc));
      exit (EXIT_FAILURE);
    }

  sockfd = socket (addrs->ai_family, addrs->ai_socktype, addrs->ai_protocol);
  if (sockfd < 0)
    {
      perror ("socket");
      exit (EXIT_FAILURE);
    }

  if (setsockopt (sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof (yes)) < 0)
    {
      perror ("setsockopt");
      exit (EXIT_FAILURE);
    }

  rc = bind (sockfd, addrs->ai_addr, addrs->ai_addrlen);
  if (rc < 0)
    {
      perror ("bind");
      exit (EXIT_FAILURE);
    }

  freeaddrinfo (addrs);

  rc = listen (sockfd, SOMAXCONN);
  if (rc < 0)
    {
      perror ("listen");
      exit (EXIT_FAILURE);
    }

  signal (SIGPIPE, SIG_IGN);

  while (run)
    {
      struct sockaddr from;
      socklen_t fromlen = sizeof (from);
      char host[NI_MAXHOST];
      int fd;
      FILE *fh;

      fd = accept (sockfd, &from, &fromlen);
      if (fd < 0)
	{
	  perror ("accept");
	  continue;
	}

      rc = getnameinfo (&from, fromlen, host, sizeof (host),
			NULL, 0, NI_NUMERICHOST);
      if (rc == 0)
	printf ("connection from %s\n", host);
      else
	printf ("getnameinfo: %s\n", gai_strerror (rc));

      fh = fdopen (fd, "w+");
      if (!fh)
	{
	  perror ("fdopen");
	  close (fd);
	  continue;
	}

      smtp (fh, ctx);

      fclose (fh);
    }

  close (sockfd);
  gsasl_done (ctx);

  return 0;
}
bool ServerSocketInterface::sendActivationTokenMail(const QString &nickname, const QString &recipient, const QString &token)
{
    QString tmp = settingsCache->value("smtp/connection", "tcp").toString();
    SmtpClient::ConnectionType connection = SmtpClient::TcpConnection;
    if(tmp == "ssl")
        connection = SmtpClient::SslConnection;
    else if(tmp == "tls")
        connection = SmtpClient::TlsConnection;

    tmp = settingsCache->value("smtp/auth", "plain").toString();
    SmtpClient::AuthMethod auth = SmtpClient::AuthPlain;
    if(tmp == "login")
        auth = SmtpClient::AuthLogin;

    QString host = settingsCache->value("smtp/host", "localhost").toString();
    int port = settingsCache->value("smtp/port", 25).toInt();
    QString username = settingsCache->value("smtp/username", "").toString();
    QString password = settingsCache->value("smtp/password", "").toString();
    QString email = settingsCache->value("smtp/email", "").toString();
    QString name = settingsCache->value("smtp/name", "").toString();
    QString subject = settingsCache->value("smtp/subject", "").toString();
    QString body = settingsCache->value("smtp/body", "").toString();

    if(email.isEmpty())
    {
        qDebug() << "[MAIL] Missing email field" << endl;
        return false;
    }
    if(body.isEmpty())
    {
        qDebug() << "[MAIL] Missing body field" << endl;
        return false;
    }
    if(recipient.isEmpty())
    {
        qDebug() << "[MAIL] Missing recipient field" << endl;
        return false;
    }
    if(token.isEmpty())
    {
        qDebug() << "[MAIL] Missing token field" << endl;
        return false;
    }

    SmtpClient smtp(host, port, connection);
    smtp.setUser(username);
    smtp.setPassword(password);
    smtp.setAuthMethod(auth);

    MimeMessage message;
    EmailAddress sender(email, name);
    message.setSender(&sender);
    EmailAddress to(recipient, nickname);
    message.addRecipient(&to);
    message.setSubject(subject);

    MimeText text;
    text.setText(body.replace("%username", nickname).replace("%token", token));
    message.addPart(&text);

    // Now we can send the mail

    if (!smtp.connectToHost()) {
        qDebug() << "[MAIL] Failed to connect to host" << host << "on port" << port;
        return false;
    }

    if (!smtp.login()) {
        qDebug() << "[MAIL] Failed to login as " << username;
        return false;
    }

    if (!smtp.sendMail(message)) {
        qDebug() << "[MAIL] Failed to send mail to " << recipient;
        return false;
    }

    smtp.quit();
    qDebug() << "[MAIL] Sent activation email to " << recipient << " for nickname " << nickname;
    return true;
}
예제 #8
0
파일: mta.c 프로젝트: ssvlab/esbmc-gpu
int
mta_smtp (int argc, char **argv)
{
  int on = 1;
  struct sockaddr_in address;
  int fd;
  
  fd = socket (PF_INET, SOCK_STREAM, 0);
  if (fd < 0)
    {
      mu_error ("%s: socket: %s", progname, strerror (errno));
      return 1;
    }

  setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on));

  memset (&address, 0, sizeof (address));
  address.sin_family = AF_INET;
  address.sin_addr.s_addr = INADDR_ANY;

  if (port)
    {
      address.sin_port = htons (port);
      if (bind (fd, (struct sockaddr *) &address, sizeof (address)) < 0)
	{
	  close (fd);
	  mu_error ("%s: bind: %s", progname, strerror(errno));
	  return 1;
	}
    }
  else
    {
      int status;
      
      port = 1023;
      do
	{
	  if (++port >= 65535)
	    {
	      mu_error ("%s: can't bind socket: all ports in use?",
			progname);
	      return 1;
	    }
	  address.sin_port = htons (port);
	  status = bind (fd, (struct sockaddr *) &address, sizeof (address));
	}
      while (status < 0);
    }

  listen (fd, 5);
  printf ("%d\n", port);
  fclose (stdout);
  while (1)
    {
      fd_set rfds;
      struct sockaddr_in his_addr;
      int sfd, status;
      socklen_t len;

      FD_ZERO (&rfds);
      FD_SET (fd, &rfds);
      
      status = select (fd + 1, &rfds, NULL, NULL, NULL);
      if (status == -1)
	{
	  if (errno == EINTR)
	    continue;
	  mu_error ("%s: select: %s", progname, strerror (errno));
	  return 1;
	}

      len = sizeof (his_addr);
      if ((sfd = accept (fd, (struct sockaddr *)&his_addr, &len)) < 0)
	{
	  mu_error ("%s: accept: %s", progname, strerror (errno));
	  return 1;
	}

      smtp (sfd);
      break;
    }
  
  return 0;
}