Google SMTP server fails - go

I get the following error when attempting to use Google's SMTP server.
535 5.7.8 Username and Password not accepted. Learn more at 5.7.8 https://support.google.com/mail/?p=BadCredentials fa15sm2375541pjb.40 - gsmtp
This is my code:
// Sender data.
from := req.FormValue("email")
//password := "xxxx" //<- log in password fails
password := "xxxx" // <- app password fails
// Receiver email address.
to := []string{
"myemail#gmail.com",
}
// smtp server configuration.
smtpHost := "smtp.gmail.com"
smtpPort := "587"
msg := req.FormValue("name") + "\n" + req.FormValue("message")
message := []byte(msg)
auth := smtp.PlainAuth("", from, password, smtpHost)
err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, to, message)
if err != nil {
tmp.Message = "Message not sent: " + err.Error()
htmlTags["contact"] = tmp
err = tmpl.ExecuteTemplate(w, "send_failure", htmlTags["contact"])
} else {
tmp.Message = "Message sent"
htmlTags["contact"] = tmp
err = tmpl.ExecuteTemplate(w, "send_success", htmlTags["contact"])
}
} else {
tmp.Message = "You message has not been sent. Cookies are required to send messages."
htmlTags["contact"] = tmp
err = tmpl.ExecuteTemplate(w, "send_failure", htmlTags["contact"])
}
The account has 2FA enabled and app password is used.
Allow less secure apps: ON
The sending code also lives on a server with a self signing cert giving the following error:
Certificate - missing
This site is missing a valid, trusted certificate (net::ERR_CERT_AUTHORITY_INVALID).

Provided your username and password is correct, these are the steps to get Gmail working from any client.
# Visit https://accounts.google.com
#
# 1. Click on [Security] menu
# 2. Scroll to section [Less secure app access] and set it to ON
# 3. Scroll to section [Signing in to Google] and set [Use your phone to sign in] to OFF
# 4. Scroll to section [Signing in to Google] and set [2-step Verification] to OFF
Now a simple text/plain email example to send:
To: "Jane Doe" <jane#gmail.com>
From: "John Doe" <john#gmail.com>
Subject: A text/plain email
MIME-Version: 1.0 (Created with SublimeText 3)
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Good morning.
This is a message in text/plain format.
It contains text/plain.
It contains no base64 inline images or attachments.
Each line is no more than 76 characters in length.
Please reach out if you have any questions.
Thank you,
John Doe
SENIOR DEVELOPER
XYZ Solutions Inc.
P | 999.555.1234
Then, you can use CURL to send it:
# GMAIL TEST - text-plain.eml
curl --verbose -ssl smtps://smtp.gmail.com:465 --login-options AUTH=PLAIN --user john#gmail.com:passwword123 --mail-from john#gmail.com --mail-rcpt jane#gmail.com --mail-rcpt-allowfails --upload-file text-plain.eml

Related

FTP Arduino issue with ESP8266

Trying to do FTP with my router from an ESP8266 WiFi-board and using the Arduino-IDE, I keep getting the following error message:
331 Password required for anonymous.
My code looks like this:
if (client.connect(server, 21)) { // 21 = FTP server
Serial.println(F("Command connected FIRST TIME"));
} else {
Serial.println(F("Command connection failed FIRST TIME"));
}
eRcv();
Serial.println("OUTPUT BUFFER 1");
Serial.println(outBuf);
client.println(F("USER anonymous"));
eRcv();
Serial.println("OUTPUT BUFFER 2");
Serial.println(outBuf);
client.println(F("PASS anonymous"));
eRcv();
Serial.println("OUTPUT BUFFER 3");
Serial.println(outBuf);
client.println(F("SYST"));
eRcv();
Serial.println("OUTPUT BUFFER 4");
Serial.println(outBuf);
client.println(F("Type I"));
eRcv();
My log looks like that:
WiFi connected; IP address: 192.168.178.33
Command connected FIRST TIME
OUTPUT BUFFER 1
220 FRITZ!Box7490 FTP server ready.
OUTPUT BUFFER 2
331 Password required for anonymous.
As you can see, the error message I receive (i.e. err 331) happens already at cmd nr 2 (i.e. "PASS anonymous2).
The router is set to accept an anonymous FTP (that should not be the problem). The router, of course, is set to allow FTP.
I read something about a "passive mode" (client.println(F("PASV"));) but it seems to me that the "PASS anonymous" should go through independent of PASV-mode ore not. Is this correct ?
Are there any other suggestions of what to do here ?
Much appreciated!
P.S. For completion, the FTP-receive (delivering the "outBuf" from the example-code above) looks like this:
//-------------- FTP receive
byte eRcv() {
byte respCode;
byte thisByte;
long StartTimeoutTime = millis();
while (!client.available() && (millis() - StartTimeoutTime < 1000))
{ // wait for answer with 1 second timeout
delay(1);
}
if (millis() - StartTimeoutTime >= 1000)
{
efail();
return 0;
}
respCode = client.peek();
outCount = 0;
while (client.available()) {
thisByte = client.read();
//Serial.write(thisByte);
if (outCount < 127) {
outBuf[outCount] = thisByte;
outCount++;
outBuf[outCount] = 0;
}
}
if (respCode >= '4') {
efail();
return 0;
}
return 1;
} // eRcv()
Anonymous authentication with FTP still requires that you send a username and a password. Traditionally the username is anonymous and an email address is used as a password. Something like user#test.com works fine. Here is a link to RFC 959, File Transfer Protocol.
From here it looks like you might not be waiting long enough for the server to send the 220 message before you send the USER. After you connect, wait for the server to finish sending its welcome message. Then send your USER, wait for the 331, then send your PASS. The server might also be sending multiple strings for the first message. Try logging into the FTP server with the commandline client for your o/s and see exactly what it's sending you, and adjust your code for that.

.Net "WSS header is missing from request. Can't do username token authentication." error

I'm trying to connect to Oracle Primavera via Oracle's Web API. Unfortunately there is not much documentation about it. I have added Primavera Web Service into my project.
So far I have following code:
Dim authService As New AuthenticationService.AuthenticationService
Dim loginObj As New AuthenticationService.Login()
Dim loginResponse As AuthenticationService.LoginResponse
authService.CookieContainer = New System.Net.CookieContainer()
authService.Url = "http://" + hostName + ":" + port + "/p6ws/services/AuthenticationService"
loginObj.UserName = userName
loginObj.Password = passwd
loginObj.DatabaseInstanceId = 1
loginObj.DatabaseInstanceIdSpecified = True
cookieContainer = authService.CookieContainer
loginResponse = authService.Login(loginObj)
Return loginResponse.Return
In authService.Login I receive "WSS header is missing from request. Can't do username token authentication."
In Primavera I have set the authentication model to cookie, but no results. What is missing?
In Primavera I have set the authentication model to cookie, but no results.
What is missing?
Restart Primavera Web Service.
I had the same error: "WSS header is missing from request. Can not do username token authentication."
I did: Primavera P6 Administrator - Primavera P6 Configuration - Web Services - Security - Authentication - Mode - Cookies.
And my code on Delphi began to run.
var
i: integer;
projLoad: CreateProjects;
projList: ProjectPortType;
projFieldLoad: Array_Of_ProjectFieldType;
_login: Login;
loginReturn: LoginResponse;
servicePort: AuthenticationServicePortType;
projectServicePort: ProjectPortType;
_status: Status;
begin
SetLength(projFieldLoad, 6);
projFieldLoad[0] := ProjectFieldType.ObjectId;
projFieldLoad[1] := ProjectFieldType.Id;
projFieldLoad[2] := ProjectFieldType.Name_;
projFieldLoad[3] := ProjectFieldType.StartDate;
projFieldLoad[4] := ProjectFieldType.FinishDate;
projFieldLoad[5] := ProjectFieldType.Status;
servicePort := GetAuthenticationServicePortType();
_login := Login.Create;
_login.UserName := 'admin';
_login.Password := 'admin';
loginReturn := servicePort.Login(_login);
projectServicePort := GetProjectPortType();
projLoad := projectServicePort.ReadProjects(projFieldLoad, '', '');
for i := 0 to Length(projLoad) - 1 do
begin
ShowMessage(IntToStr(projLoad[i].ObjectId));
ShowMessage(projLoad[i].Id);
ShowMessage(projLoad[i].Name_);
if Assigned(projLoad[i].StartDate) then
ShowMessage(DateToStr(projLoad[i].StartDate.AsDateTime));
if Assigned(projLoad[i].FinishDate) then
ShowMessage(DateToStr(projLoad[i].FinishDate.AsDateTime));
_status := projLoad[i].Status;
if _status = Status.Planned then
ShowMessage('Planned');
if _status = Status.Active then
ShowMessage('Active');
end;
P.S. Web services and software installed on my laptop

Golang code to upload a file into personal box account

When I give this snippet of code in a golang program after recieving the access token:
f, err := ioutil.ReadFile("C:\\Users\\vembu\\Desktop\\hi.txt")
ioutil.WriteFile("hi.txt", f, 0x777)
r, _ := http.NewRequest("POST", urlStr, bytes.NewBuffer(f))
r.Header.Add("Authorization", "Bearer "+accessobj.Access_token)
r.Header.Add("attributes", "{\"name\":\"hi.txt\",\"parent\":{\"id\":\"3098791209\"}}")r.Header.Add("file", "hi.txt")
I get this error:
I face &{405 Method Not Allowed 405 HTTP/1.1 1 1 map[Allow:[GET, OPTIONS, HEAD] Content-Type:[text/html;charset=UTF-8] Content-Length:[0] Date:[Thu, 12 Mar 2015 13:07:32 GMT] Age:[0] Connection:[keep-alive] Server:[ATS]] 0xc08200b8c0 0 [] false map[] 0xc08201f2b0 0xc082060980}
Can anyone please help me to solve the method to add the attributes and the file name to upload into the box account?
urlStr should be https://upload.box.com/api/2.0/files/content
https://developers.box.com/docs/#files-upload-a-file
As they show in the docs, you may want to try out your queries using curl first:
curl https://upload.box.com/api/2.0/files/content \
-H "Authorization: Bearer ACCESS_TOKEN" -X POST \
-F attributes='{"name":"tigers.jpeg", "parent":{"id":"11446498"}}' \
-F file=#myfile.jpg

python SSDP discovery error

req = ['M-SEARCH * HTTP/1.1',
'HOST: 239.255.255.250:1900',
'MAN: "ssdp:discover"',
'ST: ssdp:all',
'MX: 3',
"", ""]
req = '\r\n'.join(req)
sock = socket(AF_INET, SOCK_DGRAM)
[sock.sendto(req, ('239.255.255.250',1900)) for i in range(3)]
resp, (addr,port) = sock.recvfrom(1024)
the SSDP discovery request i perform with this code retrieves me only the rootdevice instead of all the LAN connected devices (samsung tv, sky+hd box, laptop, PCs).
does anyone know how to display all the devices?
You only wait for one answer so it seems logical that you only get one :)
This should show all of them (including the duplicates that the devices/services send).
while (True):
resp, (addr,port) = sock.recvfrom(1024)
print resp

Why the gmail API sends html emails as plain text?

I'm trying to send a html email using the gmail API but for some reasons it randomly sends the email as plain/text. It seems that Google alters the content type header I set. Is there any reason for that? The email content is exactly same all the time (as I test it). Is the API still experimental?
Sometimes when it works it also adds Content-Type: multipart/alternative; (although I never set it).
The encoding process looks as below. The code is Go but I guess it self explanatory and the process is language agnostic.
header := make(map[string]string)
header["From"] = em.From.String()
header["To"] = em.To.String()
// header["Subject"] = encodeRFC2047(em.Subject)
header["Subject"] = em.Subject
header["MIME-Version"] = "1.0"
header["Content-Type"] = "text/html; charset=\"utf-8\""
// header["Content-Transfer-Encoding"] = "base64"
header["Content-Transfer-Encoding"] = "quoted-printable"
var msg string
for k, v := range header {
msg += fmt.Sprintf("%s: %s\r\n", k, v)
}
msg += "\r\n" + em.Message
gmsg := gmail.Message{
Raw: encodeWeb64String([]byte(msg)),
}
_, err = gmailService.Users.Messages.Send("me", &gmsg).Do()
Hmm, are you sure it's not a bug in your program? Can you print out the entire string and paste it here?
I just used the Gmail API to send an email like:
To: <redacted>
Subject: test html email 2015-01-14 09:45:40
Content-type: text/html
<html><body><b>hello</b>world</body></html>
and it looked as expected by the recipient's end in Gmail. Well, actually looks like it got wrapped it in a multipart/alternative and added a text/plain part as well (good thing IMO):
<random trace headers>
MIME-Version: 1.0
From: <redacted>
Date: Wed, 14 Jan 2015 09:46:41 -0800
Message-ID:
Subject: test html email 2015-01-14 09:45:40
To: <redacted>
Content-Type: multipart/alternative; boundary=089e0141a9a2875c38050ca05201
--089e0141a9a2875c38050ca05201
Content-Type: text/plain; charset=UTF-8
*hello*world
--089e0141a9a2875c38050ca05201
Content-Type: text/html; charset=UTF-8
<html><body><b>hello</b>world</body></html>
--089e0141a9a2875c38050ca05201--
In any case, it's doing some parsing/sanitizing but does allow sending text/html email.

Resources