Thomas Stockbruegger
asked on
Need some help with mailto
Hello,
How can I enclose the file that I want to send with this email, and also
how can I enclose a subject?
File: C:/user/test.txt
Subject: this is a test
str_Email=”info@somebody.c om”
ShellExecute(NULL,_T("open "),"mailto :"+str_EMa il,NULL,NU LL,SW_NORM AL);
Thank you very much for your help.
Best regards from
Thomas
How can I enclose the file that I want to send with this email, and also
how can I enclose a subject?
File: C:/user/test.txt
Subject: this is a test
str_Email=”info@somebody.c
ShellExecute(NULL,_T("open
Thank you very much for your help.
Best regards from
Thomas
ASKER
Hi Sara,
thank you for your post. How can I enclose this code to ShellExecute?
ShellExecute(NULL,_T("open "),"mailto :user@exam ple.com?su bject="Som e Subject" &body="Some Content" ?Attach="c:\temp\test.txt" );
will not work.
Thank you.
Thomas
thank you for your post. How can I enclose this code to ShellExecute?
ShellExecute(NULL,_T("open
will not work.
Thank you.
Thomas
you may try a std::stringstream and concatenate like
if your mfc project uses wide characters (called UNICODE by MS) you would use wstring and wostringstream like
you also could use CString and _T macro which automatically would do the Switch between ansi and wide characters.
if you get compile errors post the errors and the code lines the Errors refer to.
Sara
#include <sstream>
....
std::string quoted_string(const std::string & str) { std::string s = "\""; s += str; s += "\""; return s; }
std::string stremail = "user@example.com";
std::string strsubject = "some subject";
std::string strbody = "some text";
std::string strattach= "c:\\temp\\test.txt";
std::ostringstream oss;
oss << "mailto:"
<< stremail
<< "?subject="<<quoted_string(strsubject)
<<" &Body="<< quoted_string(strbody)
<< " ?Attach="<< quoted_string(strattach);
ShellExecute(NULL, "open", oss.str().c_str, NULL, NULL, SW_SHOW);
if your mfc project uses wide characters (called UNICODE by MS) you would use wstring and wostringstream like
#include <sstream>
....
std::wstring quoted_string(const std::wstring & str) { std::wstring s = L"\""; s += str; s += L"\""; return s; }
std::wstring stremail = L"user@example.com";
std::wstring strsubject = L"some subject";
std::wstring strbody = L"some text";
std::wstring strattach= L"c:\\temp\\test.txt";
std::wostringstream oss;
oss << L"mailto:"
<< stremail
<< L"?subject="<<quoted_string(strsubject)
<<L" &Body="<< quoted_string(strbody)
<< L" ?Attach="<< quoted_string(strattach);
ShellExecute(NULL, L"open", oss.str().c_str, NULL, NULL, SW_SHOW);
you also could use CString and _T macro which automatically would do the Switch between ansi and wide characters.
if you get compile errors post the errors and the code lines the Errors refer to.
Sara
ASKER
Hi Sara, did you mean this?
// EMAILDlg.cpp : Implementierungsdatei
//
#include "stdafx.h"
#include "EMAIL.h"
#include "EMAILDlg.h"
#include ".\emaildlg.h"
#include <sstream>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
.
.
.
.
//######################## ########## ########## ########## ########## ##########
void CEMAILDlg::OnBnClickedButt on_Email()
{
std::string quoted_string(const std::string & str) { std::string s = "\""; s += str; s += "\""; return s; }
std::string stremail = "user@example.com";
std::string strsubject = "some subject";
std::string strbody = "some text";
std::string strattach= "c:\\temp\\test.txt";
std::ostringstream oss;
oss << "mailto:"
<< stremail
<< "?subject="<<quoted_string (strsubjec t)
<<" &Body="<< quoted_string(strbody)
<< " ?Attach="<< quoted_string(strattach);
ShellExecute(NULL, "open", oss.str().c_str, NULL, NULL, SW_SHOW);
}
//######################## ########## ########## ########## ########## ##########
I will get this error:
c:\Dokumente und Einstellungen\Administrato r\Eigene Dateien\Visual Studio Projects\EMAIL\EMAILDlg.cp p(192) : error C2601: 'quoted_string': Lokale Funktionsdefinitionen sind unzulässig
c:\Dokumente und Einstellungen\Administrato r\Eigene Dateien\Visual Studio Projects\EMAIL\EMAILDlg.cp p(206) : error C2664: 'ShellExecuteA': Konvertierung des Parameters 3 von 'const char *(void) const' in 'LPCSTR' nicht möglich
Es gibt keinen Kontext, in dem diese Konvertierung möglich
// EMAILDlg.cpp : Implementierungsdatei
//
#include "stdafx.h"
#include "EMAIL.h"
#include "EMAILDlg.h"
#include ".\emaildlg.h"
#include <sstream>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
.
.
.
.
//########################
void CEMAILDlg::OnBnClickedButt
{
std::string quoted_string(const std::string & str) { std::string s = "\""; s += str; s += "\""; return s; }
std::string stremail = "user@example.com";
std::string strsubject = "some subject";
std::string strbody = "some text";
std::string strattach= "c:\\temp\\test.txt";
std::ostringstream oss;
oss << "mailto:"
<< stremail
<< "?subject="<<quoted_string
<<" &Body="<< quoted_string(strbody)
<< " ?Attach="<< quoted_string(strattach);
ShellExecute(NULL, "open", oss.str().c_str, NULL, NULL, SW_SHOW);
}
//########################
I will get this error:
c:\Dokumente und Einstellungen\Administrato
c:\Dokumente und Einstellungen\Administrato
Es gibt keinen Kontext, in dem diese Konvertierung möglich
quoted_string is a helper function which should be placed above your function
you also can put it into the CEMAILDlg class as a member function (best directly as inline in the class definition). don't forget to #include <string> in the header file if you do so.
the ShellExecute call has to be changed to
ShellExecute(NULL, "open", oss.str().c_str(), NULL, NULL, SW_SHOW);
cstr is a function of std::string, which returns a const pointer to char what is equivalent to LPCSTR.
Sara
std::string quoted_string(const std::string & str) { std::string s = "\""; s += str; s += "\""; return s; }
void CEMAILDlg::OnBnClickedButton_Email()
{
...
you also can put it into the CEMAILDlg class as a member function (best directly as inline in the class definition). don't forget to #include <string> in the header file if you do so.
the ShellExecute call has to be changed to
ShellExecute(NULL, "open", oss.str().c_str(), NULL, NULL, SW_SHOW);
cstr is a function of std::string, which returns a const pointer to char what is equivalent to LPCSTR.
Sara
ASKER
Hi Sara, I will get this result:
will not enclose the file.
// EMAILDlg.h : Headerdatei
#pragma once
#include <string>
#include <sstream>
.
.
.
// CEMAILDlg Dialogfeld
class CEMAILDlg : public CDialog
{
// Konstruktion
public:
CEMAILDlg(CWnd* pParent = NULL); // Standardkonstruktor
// Dialogfelddaten
enum { IDD = IDD_EMAIL_DIALOG };
protected:
virtual void DoDataExchange(CDataExchan ge* pDX); // DDX/DDV-Unterstützung
.
.
.
.
.
// EMAILDlg.cpp : Implementierungsdatei
#include "stdafx.h"
#include "EMAIL.h"
#include "EMAILDlg.h"
#include ".\emaildlg.h"
#include <sstream>
#include <string>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
.
.
.
.
.
std::string quoted_string(const std::string & str) { std::string s = "\""; s += str; s += "\""; return s; }
//######################## ########## ########## ########## ########## ########## ########## #
void CEMAILDlg::OnBnClickedButt onEmail()
{
std::string stremail = "user@example.com";
std::string strsubject = "some subject";
std::string strbody = "some text";
std::string strattach= "o:\\Verwaltung\\1111\\1.d oc";
std::ostringstream oss;
oss << "mailto:"
<< stremail
<< "?subject="<<quoted_string (strsubjec t)
<<" &Body="<< quoted_string(strbody)
<< " ?Attach="<< quoted_string(strattach);
ShellExecute(NULL, "open", oss.str().c_str(), NULL, NULL, SW_SHOW);
}
//######################## ########## ########## ########## ########## ########## ########## #
will not enclose the file.
// EMAILDlg.h : Headerdatei
#pragma once
#include <string>
#include <sstream>
.
.
.
// CEMAILDlg Dialogfeld
class CEMAILDlg : public CDialog
{
// Konstruktion
public:
CEMAILDlg(CWnd* pParent = NULL); // Standardkonstruktor
// Dialogfelddaten
enum { IDD = IDD_EMAIL_DIALOG };
protected:
virtual void DoDataExchange(CDataExchan
.
.
.
.
.
// EMAILDlg.cpp : Implementierungsdatei
#include "stdafx.h"
#include "EMAIL.h"
#include "EMAILDlg.h"
#include ".\emaildlg.h"
#include <sstream>
#include <string>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
.
.
.
.
.
std::string quoted_string(const std::string & str) { std::string s = "\""; s += str; s += "\""; return s; }
//########################
void CEMAILDlg::OnBnClickedButt
{
std::string stremail = "user@example.com";
std::string strsubject = "some subject";
std::string strbody = "some text";
std::string strattach= "o:\\Verwaltung\\1111\\1.d
std::ostringstream oss;
oss << "mailto:"
<< stremail
<< "?subject="<<quoted_string
<<" &Body="<< quoted_string(strbody)
<< " ?Attach="<< quoted_string(strattach);
ShellExecute(NULL, "open", oss.str().c_str(), NULL, NULL, SW_SHOW);
}
//########################
you may put the line with ?Attach= directly after ?subject line and above the &Body= line.
i will try to find some more samples.
Sara
i will try to find some more samples.
Sara
ASKER
ok. can you try
<< "?attachment=\"\"o:\\..... \"\""
both before body and after body?
see the doubled quotes around the file path.
if that worked you could use
quoted_string(quoted_strin g(strattac h)) to get the doubled "" into the c++ string.
i searched a long time and some people said they have got it working but no solution which was confirmed by others.
Sara
<< "?attachment=\"\"o:\\.....
both before body and after body?
see the doubled quotes around the file path.
if that worked you could use
quoted_string(quoted_strin
i searched a long time and some people said they have got it working but no solution which was confirmed by others.
Sara
ASKER
Hi Sara, same result ... (both ways) will not work.
std::string stremail = "user@example.com";
std::string strsubject = "some subject";
std::string strbody = "some text";
std::string strattach= "O:\\Verwaltung\\1111\\1.d
std::ostringstream oss;
oss << "mailto:"
<< stremail
<< "?subject="<<quoted_string
<< "?attachment=\"\"O:\\Verwa
<<" &Body="<< quoted_string(strbody);
ShellExecute(NULL, "open", oss.str().c_str(), NULL, NULL, SW_SHOW);
when I put the code behind Body the text="?attachment=\"\"O:\\
in the specs they say that only the first parameter was prefixed by a ?
the other parameters are prefixed by &
Sara
the other parameters are prefixed by &
Sara
ASKER
Hi Sara, both ways will not work. No attachment.
std::string stremail = "user@example.com";
std::string strsubject = "some subject";
std::string strbody = "some text";
std::string strattach= "O:\\Verwaltung\\1111\\1.d oc";
std::ostringstream oss;
oss << "mailto:"
<< stremail
<< "?subject="<<quoted_string (strsubjec t)
<< "&attachment=\"\"O:\\Verwa ltung\\111 1\\1.doc\" \""
<<" &Body="<< quoted_string(strbody);
<< stremail
<< "?subject="<<quoted_string (strsubjec t)
<< " &Body="<< quoted_string(strbody)
<<"&attachment=\"\"O:\\Ver waltung\\1 111\\1.doc \"\"";
ShellExecute(NULL, "open", oss.str().c_str(), NULL, NULL, SW_SHOW);
std::string stremail = "user@example.com";
std::string strsubject = "some subject";
std::string strbody = "some text";
std::string strattach= "O:\\Verwaltung\\1111\\1.d
std::ostringstream oss;
oss << "mailto:"
<< stremail
<< "?subject="<<quoted_string
<< "&attachment=\"\"O:\\Verwa
<<" &Body="<< quoted_string(strbody);
<< stremail
<< "?subject="<<quoted_string
<< " &Body="<< quoted_string(strbody)
<<"&attachment=\"\"O:\\Ver
ShellExecute(NULL, "open", oss.str().c_str(), NULL, NULL, SW_SHOW);
ASKER
Sara, even if this is not working with the file attachament...can you let me know how I can use multi-line text with strbody
f.e.
std::string strbody = "With kindest regards\r\nThomas"; = will not work =With kindest regardsThomas
should look like on the email
With kindest regards
Thomas
f.e.
std::string strbody = "With kindest regards\r\nThomas"; = will not work =With kindest regardsThomas
should look like on the email
With kindest regards
Thomas
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Sara, even if we get no luck with the attachment.
Have a nice day.
Best regards
Thomas
Have a nice day.
Best regards
Thomas
you might get more success with attachments when using a html mail request rather than mailto. i saw examples of html requests when looking for mailto examples. unfortunately i can't help you with html as it is not in my expertise. but i am pretty sure that there are plenty of samples around.
another way could be to use an smtp client for example like the one i found at www.port25.com/Free-Trial
Sara
another way could be to use an smtp client for example like the one i found at www.port25.com/Free-Trial
Sara
mailto:user@example.com?su
see https://msdn.microsoft.com/en-us/library/aa767737.aspx for more Information.
Sara