之前写过一篇博文,通过MAPI实现调用邮箱客户端发送邮件带附件,当时对ShellExecute研究不深,以为ShellExecute不能带附件,因为项目需求原因(MAPI只能调用Foxmail和Outlook邮箱客户端,无法调用网易邮箱大师),不得不回头再次研究ShellExecute函数,最后发现ShellExecute可以完美调用Foxmail、网易邮箱大师、Outlook(单次发送只能添加一个附件)。因为我们安装完Foxmail、网易大师后,系统右键里发送到里有他们的快捷方式,所以就是在这里入手的,它们的快捷方式存放在系统路径下 C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\SendTo (这是我的电脑上的位置,具体根据当前系统登录用户目录下找)

Foxmail:

int SharedByFoxmail()
{
TCHAR szPath[MAX_PATH] = { };
SHGetSpecialFolderPath(NULL, szPath, CSIDL_SENDTO, FALSE);
CString strClient;
strClient.Format(L"%ls", szPath);
strClient += L"\\Foxmail.lnk";//拿到快捷方式的绝对路径 CString strRecv = “example@.com”;//收件人
CString FilePath = "\"C:\\Users\\Administrator\\Desktop\\123.txt\" \"C:\\Users\\Administrator\\Desktop\\image.png\"";//多个附件发送时 路径要用双引号括起来,路径之间用空格隔开 ShellExecute(NULL, L"open", strClient,FilePath, L"", SW_SHOW); //填写收件人
HWND hWnd = NULL;
int n = ;
do
{
Sleep();
hWnd = ::FindWindow(L"TFoxComposeForm.UnicodeClass", NULL);
n--;
} while (n && (hWnd == NULL || !::IsWindowVisible(hWnd))); if (hWnd == NULL)
{
return -;
} HWND hChildWnd1 = NULL;
HWND hChildWnd2 = NULL;
HWND hChildWnd31 = NULL;
HWND hChildWnd32 = NULL;
HWND hChildWnd33 = NULL;
if (hWnd != NULL)
{
::SetForegroundWindow(hWnd); hChildWnd1 = ::FindWindowEx(hWnd, , L"TFoxComposeFrame.UnicodeClass", NULL);
hChildWnd2 = ::FindWindowEx(hChildWnd1, , L"TLayoutManager", NULL);
hChildWnd31 = ::FindWindowEx(hChildWnd2, , L"TFMZRichEdit.UnicodeClass", NULL);
//抄送
hChildWnd32 = ::FindWindowEx(hChildWnd2, hChildWnd31, L"TFMZRichEdit.UnicodeClass", NULL);
if (hChildWnd32 != NULL)
{
DWORD SelfThreadId = GetCurrentThreadId();//获取本身的线程ID
DWORD ForeThreadId = GetWindowThreadProcessId(hChildWnd32, NULL);//根据窗口句柄获取线程ID
AttachThreadInput(ForeThreadId, SelfThreadId, true);//附加线程 // WCHAR* szTest = L"comor_86sssss163.com";
//::SendMessage(hChildWnd32, WM_SETTEXT, 0, (LPARAM)strCC.GetBuffer(0));
//strCC.ReleaseBuffer();
} //收件人
hChildWnd33 = ::FindWindowEx(hChildWnd2, hChildWnd32, L"TFMZRichEdit.UnicodeClass", NULL);
if (hChildWnd33 != NULL)
{
DWORD SelfThreadId = GetCurrentThreadId();//获取本身的线程ID
DWORD ForeThreadId = GetWindowThreadProcessId(hChildWnd33, NULL);//根据窗口句柄获取线程ID
AttachThreadInput(ForeThreadId, SelfThreadId, true);//附加线程 // WCHAR* szTest = L"comor_86@163.com";
::SendMessage(hChildWnd33, WM_SETTEXT, , (LPARAM)strRecv.GetBuffer());
strRecv.ReleaseBuffer();
}
}
return 0;
}

网易邮箱大师:

int SharedByNetease()
{
TCHAR szPath[MAX_PATH] = { };
SHGetSpecialFolderPath(NULL, szPath, CSIDL_SENDTO, FALSE);
CString strClient;
strClient.Format(L"%ls", szPath);
strClient += L"\\Foxmail.lnk";//拿到快捷方式的绝对路径 CString strRecv = “example@.com”;//收件人
CString FilePath = "\"C:\\Users\\Administrator\\Desktop\\123.txt\" \"C:\\Users\\Administrator\\Desktop\\image.png\"";//多个附件发送时 路径要用双引号括起来,路径之间用空格隔开 ShellExecute(NULL, L"open", strClient,FilePath, L"", SW_SHOW); //填写收件人
HWND hWnd = NULL;
int n = ;
do
{
Sleep();
hWnd = ::FindWindow(L"MailWriteWindow", NULL);
n--;
} while (n && (hWnd == NULL || !::IsWindowVisible(hWnd))); if (hWnd == NULL)
{
return -;
} ::SetForegroundWindow(hWnd); hWnd = NULL;
n = ;
do
{
Sleep();
hWnd = ::FindWindow(L"MailWriteWindow", NULL);
n--;
} while (hWnd == NULL && n); if (hWnd == NULL)
{
return -;
} ::SendMessage(hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(, ));//模拟鼠标左键按下 Sleep(); SendKeys(strRecv);
return 0;
}
....................... ///////////////////////////////////////////////// void SendKeys(CString msg)
{
USES_CONVERSION;
wchar_t* data = T2W(msg.GetBuffer());
int len = wcslen(data); for (int i = ; i<len; i++)
{
SendUnicode(data[i]);
}
}

OutLook:

int SharedByOutlook()
{
CString strFile= "\"C:\\Users\\Administrator\\Desktop\\123.txt\""
CString strRecv= “example@.com”;//收件人 CString strPara;
strPara = "/a \"";
strPara += strFile;
strPara +="\"";//附件路径用双引号括起来,方式文件名中有空格造成调用失败 //获取outlook安装路径
CString strPath = ReadOutlookPath();
if (!strPath.IsEmpty())
{
//添加判断文件是否存在
if (PathFileExists(strPath + "outlook.exe"))
{
ShellExecute(NULL,L"open",L"outlook.exe",strPara,strPath,SW_SHOW);
}
} HWND hWnd = NULL;
int n = ;
do
{
Sleep();
hWnd = ::FindWindow(L"rctrl_renwnd32", NULL);
n--;
} while (n && (hWnd == NULL || !::IsWindowVisible(hWnd))); if (hWnd == NULL)
{
return -;
} ::SetForegroundWindow(hWnd); TCHAR* szBuffer = strRecv.GetBuffer();
EnumChildWindows(hWnd, EnumChildWindowsProc, (LPARAM)szBuffer);
strRecv.ReleaseBuffer(); return ;
} ///////////////////////////////////////
CString CSharedHelper::ReadOutlookPath()
{
HKEY hKEY;
HKEY hKeyRoot = HKEY_LOCAL_MACHINE;
long ret = ::RegOpenKeyEx(hKeyRoot,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\OUTLOOK.EXE",
,
KEY_READ,
&hKEY);
if (ret != ERROR_SUCCESS)//如果无法打开hKEY,则中止程序的执行
{
// AfxMessageBox(L"错误:无法打开有关的hKEY");
return L"";
} TCHAR Vals[MAX_PATH] = { };
DWORD keyType;
DWORD lenIt = MAX_PATH*sizeof(TCHAR);
if (::RegQueryValueEx(hKEY, L"Path", , &keyType, (BYTE*)Vals, &lenIt) != ERROR_SUCCESS)
{
// AfxMessageBox(L"错误:RegQueryValueExA错误");
return L"";
} CString str;
str.Format(L"%ls", Vals);
return str;
} BOOL CALLBACK CSharedHelper::EnumChildWindowsProc(HWND hWnd, LPARAM lParam)
{
HWND EditNumHwnd = ::FindWindowEx(hWnd, NULL, _T("RichEdit20WPT"), NULL);
if (EditNumHwnd != NULL)
{
if (::GetWindowLong(EditNumHwnd, GWL_STYLE)&WS_VISIBLE)
{
TCHAR* str = (TCHAR*)lParam;
//::SendMessage(EditNumHwnd, WM_CHAR, WPARAM('a'), 0);//发送一个字消息
::SendMessage(EditNumHwnd, WM_SETTEXT, , (LPARAM)str); return ;
}
} return ;
}

VC++ 使用ShellExecute函数调用邮箱客户端发送邮件(可以带附件)的更多相关文章

  1. 利用Python+163邮箱授权码发送带附件的邮件

    背景 前段时间写了个自动爬虫的脚本,定时在阿里云服务器上执行,会从某个网站上爬取链接保存到txt文本中,但是脚本不够完善,我需要爬虫完毕之后通过邮件把附件给我发送过来,之前写过一个<利用Pyth ...

  2. JavaMail发送邮件、带附件邮件(完整版)

    工程目录如下: 1.准备javaMail需要的两个Jar包:mail.jar.activation.jar,然后add to build path 2.QQ邮箱开启SMTP服务,开启后,它会给你一串授 ...

  3. python发送邮件(带附件)

    python通过stmp发送qq邮件,带附件 import smtplib from email.mime.multipart import MIMEMultipart from email.mime ...

  4. CI框架发送邮件(带附件)

    最近写了一个发送带附件的邮件,发邮件挺简单的,在我这里最重要的是遇到问题,哈哈哈哈 1.主要方法看代码 public function send_mail(){ $this->load-> ...

  5. python webdriver firefox 登录126邮箱,先添加联系人,然后进入首页发送邮件,带附件。

    代码:#encoding=utf-8from selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom ...

  6. Jmail发送邮件与带附件乱码解决办法

    Jamil发送邮件的具体用法: 首先,我们要从网上下载Jamil.dll的组件,这个网上很多,然后添加引用using jmail,然后再本机或者服务器上注册一下 将jmail.dll拷贝到服务器的sy ...

  7. Qt + CURL + mimetic 发送邮件(带附件)

    使用了大名鼎鼎的CURL 开源库,以及mimetic开源库. CURL支持N多协议.功能超强,但是不能直接发邮件附件,需要自己拼mime.太麻烦,于是乎~~ mimetic主要用于构造邮件mimeti ...

  8. nodejs——发送邮件(带附件)

    用到的包是 nodemailer,简单,有效. 1.auth 中的 pass,是指“邮箱第三方登录授权码”,如何获取授权码,以QQ邮箱为例,请点击:http://jingyan.baidu.com/a ...

  9. Go smtp发送邮件,带附件

    package main import ( "net/smtp" "bytes" "time" "io/ioutil" ...

随机推荐

  1. 使用SQL语句如何实现条件判断

    客户需求是咨询如何用SQL结合decode函数实现条件判断,比如当某一列数值大于500,对应类型"大于500":当某一列数值小于500,对应类型"小于500". ...

  2. Lepus(天兔)监控MySQL部署

    http://www.dbarun.com/docs/lepus/install/lnmp/ 注意:xampp mysqldb-python版本太高会导致lepus白屏 apache版本最好选择2.2 ...

  3. SqlServer表和EXCEL数据互相复制方法

    一.SqlServer表数据复制到excel 1.新建查询,用sql语句把表数据读出来 2.然后,选择数据,右键,复制(也可以点击连同标题复制),复制到记事本中(不然会乱码) 3.然后再把记事本的内容 ...

  4. Service Fabric下删除实例并注销应用

    Service Fabric下删除实例并注销应用: 以应用名称:Application1为例 1.打开PowerShell 2.连接集群: Connect-ServiceFabricCluster - ...

  5. SQL语句提取某列中的HTML文本内容。或者说怎么用SQL语句去除所有HTML标签

    CREATE FUNCTION [dbo].[f_trimstr] ( @str NVARCHAR(MAX) ) RETURNS NVARCHAR(MAX) AS     BEGIN          ...

  6. QT5中QByteArray转QString中文乱码

    1.添加头文件 #include <QTextCodec> 2.用QTextCodec 设置格式转换 QByteArray barr; barr.insert(0,(char*)(pMsg ...

  7. 20170918-00-(代理ip检验)

    代码集编号 20170918-00 import random #随机数模块 import urllib.request #常用爬虫模块 import time from bs4 import Bea ...

  8. django 网站的搭建(1)

    使用 python django 模块来搭建自己的博客网站. 本人环境:阿里云centos7+django1.10+python3.5 使用工具:putty + winscp 1.首先安装python ...

  9. centos python2升级为python3 升级旧版本django

    阿里云centos python3 及django的配置 安装python3后 pip 会把下载的包安入python2.7 下面解决该问题 python3.5安装1,安装依赖包#yum install ...

  10. golang linux安装

    go在linux下的安装: [root@localhost src]# wget https://storage.googleapis.com/golang/go1.8.1.linux-amd64.t ...