Skip to content

Commit 549d275

Browse files
author
Eran Hammer-Lahav
committed
Feature Requests item #1873929
Add ability to include name in SMTP sender field
1 parent 3edd579 commit 549d275

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

Net/src/SMTPClientSession.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,20 @@ void SMTPClientSession::close()
133133
void SMTPClientSession::sendMessage(const MailMessage& message)
134134
{
135135
std::string response;
136-
std::string sender("<");
137-
sender.append(message.getSender());
138-
sender.append(">");
139-
int status = sendCommand("MAIL FROM:", sender, response);
136+
int status = 0;
137+
const std::string& fromField = message.getSender();
138+
std::string::size_type emailPos = fromField.find('<');
139+
if (emailPos == std::string::npos)
140+
{
141+
std::string sender("<");
142+
sender.append(fromField);
143+
sender.append(">");
144+
status = sendCommand("MAIL FROM:", sender, response);
145+
}
146+
else
147+
{
148+
status = sendCommand("MAIL FROM:", fromField.substr(emailPos, fromField.size() - emailPos), response);
149+
}
140150
if (!isPositiveCompletion(status)) throw SMTPException("Cannot send message", response);
141151
for (MailMessage::Recipients::const_iterator it = message.recipients().begin(); it != message.recipients().end(); ++it)
142152
{

0 commit comments

Comments
 (0)